plazbot-cli 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.claude/settings.local.json +15 -0
  2. package/CLAUDE.md +92 -0
  3. package/README.md +1 -1
  4. package/dist/cli.js +14 -5
  5. package/dist/commands/agent/ai-config.js +103 -0
  6. package/dist/commands/agent/chat.js +130 -34
  7. package/dist/commands/agent/copy.js +37 -0
  8. package/dist/commands/agent/create.js +80 -17
  9. package/dist/commands/agent/delete.js +3 -3
  10. package/dist/commands/agent/enable-widget.js +1 -1
  11. package/dist/commands/agent/files.js +142 -0
  12. package/dist/commands/agent/get.js +1 -2
  13. package/dist/commands/agent/index.js +14 -2
  14. package/dist/commands/agent/list.js +6 -6
  15. package/dist/commands/agent/set.js +127 -0
  16. package/dist/commands/agent/templates.js +803 -0
  17. package/dist/commands/agent/tools.js +155 -0
  18. package/dist/commands/agent/wizard.js +369 -0
  19. package/dist/commands/portal/add-agent.js +4 -4
  20. package/dist/commands/portal/list.js +5 -4
  21. package/dist/commands/whatsapp/broadcast.js +97 -0
  22. package/dist/commands/whatsapp/channels.js +86 -0
  23. package/dist/commands/whatsapp/chat.js +74 -0
  24. package/dist/commands/whatsapp/index.js +11 -2
  25. package/dist/commands/whatsapp/send-template.js +51 -14
  26. package/dist/commands/whatsapp/send.js +10 -10
  27. package/dist/commands/whatsapp/widget.js +64 -0
  28. package/dist/utils/banner.js +87 -0
  29. package/dist/utils/logger.js +27 -6
  30. package/dist/utils/ui.js +111 -0
  31. package/package.json +10 -2
  32. package/src/cli.ts +13 -5
  33. package/src/commands/agent/ai-config.ts +108 -0
  34. package/src/commands/agent/chat.ts +149 -40
  35. package/src/commands/agent/copy.ts +40 -0
  36. package/src/commands/agent/create.ts +58 -23
  37. package/src/commands/agent/delete.ts +3 -3
  38. package/src/commands/agent/enable-widget.ts +1 -1
  39. package/src/commands/agent/files.ts +158 -0
  40. package/src/commands/agent/get.ts +1 -2
  41. package/src/commands/agent/index.ts +14 -2
  42. package/src/commands/agent/list.ts +7 -7
  43. package/src/commands/agent/set.ts +137 -0
  44. package/src/commands/agent/templates.ts +843 -0
  45. package/src/commands/agent/tools.ts +161 -0
  46. package/src/commands/agent/wizard.ts +475 -0
  47. package/src/commands/portal/add-agent.ts +4 -4
  48. package/src/commands/portal/list.ts +5 -4
  49. package/src/commands/whatsapp/broadcast.ts +100 -0
  50. package/src/commands/whatsapp/channels.ts +98 -0
  51. package/src/commands/whatsapp/chat.ts +77 -0
  52. package/src/commands/whatsapp/index.ts +11 -2
  53. package/src/commands/whatsapp/send-template.ts +57 -19
  54. package/src/commands/whatsapp/send.ts +15 -14
  55. package/src/commands/whatsapp/widget.ts +67 -0
  56. package/src/utils/banner.ts +94 -0
  57. package/src/utils/logger.ts +26 -7
  58. package/src/utils/ui.ts +109 -0
  59. package/dist/commands/message/delete-webhook.js +0 -39
  60. package/dist/commands/message/index.js +0 -14
  61. package/dist/commands/message/register-webhook.js +0 -42
  62. package/dist/commands/message/send-template.js +0 -42
  63. package/dist/commands/message/send.js +0 -42
@@ -24,7 +24,7 @@ exports.enableCommand = new commander_1.Command('enable-widget')
24
24
  const agentDetails = await agent.getAgentById({ id: agentId });
25
25
  logger_1.logger.info('\n🔧 Estado actual del widget:');
26
26
  logger_1.logger.divider();
27
- logger_1.logger.info(`Agente: ${agentDetails.agent.name}`);
27
+ logger_1.logger.info(`Agente: ${agentDetails.name}`);
28
28
  logger_1.logger.divider();
29
29
  // Cambiar estado
30
30
  const newState = !options.disable; // Si --disable está presente, newState será false
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filesCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const plazbot_1 = require("plazbot");
6
+ const credentials_1 = require("../../utils/credentials");
7
+ const logger_1 = require("../../utils/logger");
8
+ const ui_1 = require("../../utils/ui");
9
+ const filesGroup = new commander_1.Command('files')
10
+ .description('Gestionar archivos de la base de conocimiento del agente');
11
+ // Listar archivos
12
+ filesGroup.command('list')
13
+ .description('Listar archivos del agente')
14
+ .argument('<agentId>', 'ID del agente')
15
+ .option('--dev', 'Usar ambiente de desarrollo', false)
16
+ .action(async (agentId, options) => {
17
+ try {
18
+ const credentials = await (0, credentials_1.getStoredCredentials)();
19
+ const agent = new plazbot_1.Agent({
20
+ workspaceId: credentials.workspace,
21
+ apiKey: credentials.apiKey,
22
+ zone: credentials.zone,
23
+ ...(options.dev && { customUrl: "http://localhost:5090" })
24
+ });
25
+ const spinner = (0, ui_1.createSpinner)('Cargando archivos...');
26
+ spinner.start();
27
+ const agentData = await agent.getAgentById({ id: agentId });
28
+ spinner.stop();
29
+ const files = agentData.files || [];
30
+ console.log((0, ui_1.section)('Archivos - ' + (agentData.name || agentId)));
31
+ if (files.length === 0) {
32
+ console.log(ui_1.theme.muted('\n No hay archivos en la base de conocimiento'));
33
+ console.log(ui_1.theme.muted(' Usa: plazbot agent files add <agentId> --url <url>\n'));
34
+ return;
35
+ }
36
+ const rows = files.map((f) => [
37
+ f.fileId || f.id || 'N/A',
38
+ f.name || f.reference || 'Sin nombre',
39
+ (f.tags || []).join(', ') || '-',
40
+ ]);
41
+ console.log((0, ui_1.createTable)(['ID', 'Nombre', 'Tags'], rows));
42
+ }
43
+ catch (error) {
44
+ const message = error instanceof Error ? error.message : 'Error desconocido';
45
+ logger_1.logger.error(message);
46
+ process.exit(1);
47
+ }
48
+ });
49
+ // Agregar archivo
50
+ filesGroup.command('add')
51
+ .description('Agregar archivo a la base de conocimiento')
52
+ .argument('<agentId>', 'ID del agente')
53
+ .requiredOption('-u, --url <url>', 'URL del archivo (PDF, DOC, DOCX)')
54
+ .option('-r, --reference <name>', 'Nombre de referencia', 'documento')
55
+ .option('-t, --tags <tags>', 'Tags separados por coma', '')
56
+ .option('--dev', 'Usar ambiente de desarrollo', false)
57
+ .action(async (agentId, options) => {
58
+ try {
59
+ const credentials = await (0, credentials_1.getStoredCredentials)();
60
+ const agent = new plazbot_1.Agent({
61
+ workspaceId: credentials.workspace,
62
+ apiKey: credentials.apiKey,
63
+ zone: credentials.zone,
64
+ ...(options.dev && { customUrl: "http://localhost:5090" })
65
+ });
66
+ const spinner = (0, ui_1.createSpinner)('Subiendo archivo...');
67
+ spinner.start();
68
+ const tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : [];
69
+ const result = await agent.addFile({
70
+ fileUrl: options.url,
71
+ reference: options.reference,
72
+ agentId,
73
+ tags,
74
+ });
75
+ spinner.succeed('Archivo agregado');
76
+ if (result?.fileId) {
77
+ logger_1.logger.label('File ID', result.fileId);
78
+ logger_1.logger.dim('El archivo esta siendo procesado. Verifica con:');
79
+ logger_1.logger.dim(`plazbot agent files status ${result.fileId}`);
80
+ }
81
+ }
82
+ catch (error) {
83
+ const message = error instanceof Error ? error.message : 'Error desconocido';
84
+ logger_1.logger.error(message);
85
+ process.exit(1);
86
+ }
87
+ });
88
+ // Verificar estado
89
+ filesGroup.command('status')
90
+ .description('Verificar estado de procesamiento de un archivo')
91
+ .argument('<fileId>', 'ID del archivo')
92
+ .option('--dev', 'Usar ambiente de desarrollo', false)
93
+ .action(async (fileId, options) => {
94
+ try {
95
+ const credentials = await (0, credentials_1.getStoredCredentials)();
96
+ const agent = new plazbot_1.Agent({
97
+ workspaceId: credentials.workspace,
98
+ apiKey: credentials.apiKey,
99
+ zone: credentials.zone,
100
+ ...(options.dev && { customUrl: "http://localhost:5090" })
101
+ });
102
+ const spinner = (0, ui_1.createSpinner)('Verificando...');
103
+ spinner.start();
104
+ const result = await agent.validateFile({ fileId });
105
+ spinner.stop();
106
+ logger_1.logger.title('Estado del archivo');
107
+ logger_1.logger.label('File ID', fileId);
108
+ logger_1.logger.label('Estado', result?.status ? 'Completado' : 'En proceso');
109
+ }
110
+ catch (error) {
111
+ const message = error instanceof Error ? error.message : 'Error desconocido';
112
+ logger_1.logger.error(message);
113
+ process.exit(1);
114
+ }
115
+ });
116
+ // Eliminar archivo
117
+ filesGroup.command('delete')
118
+ .description('Eliminar archivo de la base de conocimiento')
119
+ .argument('<agentId>', 'ID del agente')
120
+ .argument('<fileId>', 'ID del archivo')
121
+ .option('--dev', 'Usar ambiente de desarrollo', false)
122
+ .action(async (agentId, fileId, options) => {
123
+ try {
124
+ const credentials = await (0, credentials_1.getStoredCredentials)();
125
+ const agent = new plazbot_1.Agent({
126
+ workspaceId: credentials.workspace,
127
+ apiKey: credentials.apiKey,
128
+ zone: credentials.zone,
129
+ ...(options.dev && { customUrl: "http://localhost:5090" })
130
+ });
131
+ const spinner = (0, ui_1.createSpinner)('Eliminando archivo...');
132
+ spinner.start();
133
+ await agent.deleteFile({ fileId, agentId });
134
+ spinner.succeed('Archivo eliminado');
135
+ }
136
+ catch (error) {
137
+ const message = error instanceof Error ? error.message : 'Error desconocido';
138
+ logger_1.logger.error(message);
139
+ process.exit(1);
140
+ }
141
+ });
142
+ exports.filesCommand = filesGroup;
@@ -21,8 +21,7 @@ exports.getCommand = new commander_1.Command('get')
21
21
  ...(options.dev && { customUrl: "http://localhost:5090" })
22
22
  });
23
23
  // Obtener detalles del agente
24
- const agentDetails = await agent.getAgentById({ id: agentId });
25
- const agentData = agentDetails.agent;
24
+ const agentData = await agent.getAgentById({ id: agentId });
26
25
  logger_1.logger.info('\nDetalles del Agente:');
27
26
  logger_1.logger.doubleDivider();
28
27
  // Información básica
@@ -10,8 +10,14 @@ const update_1 = require("./update");
10
10
  const enable_widget_1 = require("./enable-widget");
11
11
  const chat_1 = require("./chat");
12
12
  const on_message_1 = require("./on-message");
13
+ const tools_1 = require("./tools");
14
+ const ai_config_1 = require("./ai-config");
15
+ const templates_1 = require("./templates");
16
+ const copy_1 = require("./copy");
17
+ const files_1 = require("./files");
18
+ const set_1 = require("./set");
13
19
  exports.agentCommands = new commander_1.Command('agent')
14
- .description('Comandos relacionados con agentes')
20
+ .description('Comandos relacionados con agentes de IA')
15
21
  .addCommand(list_1.listCommand)
16
22
  .addCommand(get_1.getCommand)
17
23
  .addCommand(delete_1.deleteCommand)
@@ -19,4 +25,10 @@ exports.agentCommands = new commander_1.Command('agent')
19
25
  .addCommand(update_1.updateCommand)
20
26
  .addCommand(enable_widget_1.enableCommand)
21
27
  .addCommand(chat_1.chatCommand)
22
- .addCommand(on_message_1.messageCommand);
28
+ .addCommand(on_message_1.messageCommand)
29
+ .addCommand(tools_1.toolsCommand)
30
+ .addCommand(ai_config_1.aiConfigCommand)
31
+ .addCommand(templates_1.templatesCommand)
32
+ .addCommand(copy_1.copyCommand)
33
+ .addCommand(files_1.filesCommand)
34
+ .addCommand(set_1.setCommand);
@@ -27,12 +27,12 @@ exports.listCommand = new commander_1.Command('list')
27
27
  }
28
28
  logger_1.logger.info('\nLista de Agentes:');
29
29
  logger_1.logger.doubleDivider();
30
- agents.forEach((agent, index) => {
31
- logger_1.logger.info(`${index + 1}. ID: ${agent.id}`);
32
- logger_1.logger.info(` Nombre: ${agent.name}`);
33
- logger_1.logger.info(` Estado: ${agent.enable ? '✅ Activo' : '❌ Inactivo'}`);
34
- logger_1.logger.info(` Descripción: ${agent.description}`);
35
- logger_1.logger.info(` Creado: ${new Date(agent.createdAt).toLocaleString()}`);
30
+ agents.forEach((a, index) => {
31
+ logger_1.logger.info(`${index + 1}. ID: ${a.id}`);
32
+ logger_1.logger.info(` Nombre: ${a.name}`);
33
+ logger_1.logger.info(` Estado: ${a.enable ? '✅ Activo' : '❌ Inactivo'}`);
34
+ logger_1.logger.info(` Descripción: ${a.description}`);
35
+ logger_1.logger.info(` Creado: ${a.createdAt ? new Date(a.createdAt).toLocaleString() : 'N/A'}`);
36
36
  logger_1.logger.divider();
37
37
  });
38
38
  if (options.dev) {
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setCommand = void 0;
7
+ const commander_1 = require("commander");
8
+ const plazbot_1 = require("plazbot");
9
+ const inquirer_1 = __importDefault(require("inquirer"));
10
+ const credentials_1 = require("../../utils/credentials");
11
+ const logger_1 = require("../../utils/logger");
12
+ const ui_1 = require("../../utils/ui");
13
+ const setGroup = new commander_1.Command('set')
14
+ .description('Configurar rapidamente propiedades del agente');
15
+ // Set greeting
16
+ setGroup.command('greeting')
17
+ .description('Cambiar el saludo del agente')
18
+ .argument('<agentId>', 'ID del agente')
19
+ .argument('<greeting>', 'Nuevo saludo')
20
+ .option('--dev', 'Usar ambiente de desarrollo', false)
21
+ .action(async (agentId, greeting, options) => {
22
+ try {
23
+ const credentials = await (0, credentials_1.getStoredCredentials)();
24
+ const agent = new plazbot_1.Agent({
25
+ workspaceId: credentials.workspace,
26
+ apiKey: credentials.apiKey,
27
+ zone: credentials.zone,
28
+ ...(options.dev && { customUrl: "http://localhost:5090" })
29
+ });
30
+ const spinner = (0, ui_1.createSpinner)('Actualizando saludo...');
31
+ spinner.start();
32
+ await agent.setGreeting(agentId, greeting);
33
+ spinner.succeed('Saludo actualizado');
34
+ logger_1.logger.label('Nuevo saludo', greeting);
35
+ }
36
+ catch (error) {
37
+ const message = error instanceof Error ? error.message : 'Error desconocido';
38
+ logger_1.logger.error(message);
39
+ process.exit(1);
40
+ }
41
+ });
42
+ // Set instructions (wizard)
43
+ setGroup.command('instructions')
44
+ .description('Configurar instrucciones del agente')
45
+ .argument('<agentId>', 'ID del agente')
46
+ .option('--dev', 'Usar ambiente de desarrollo', false)
47
+ .action(async (agentId, options) => {
48
+ try {
49
+ const credentials = await (0, credentials_1.getStoredCredentials)();
50
+ const agent = new plazbot_1.Agent({
51
+ workspaceId: credentials.workspace,
52
+ apiKey: credentials.apiKey,
53
+ zone: credentials.zone,
54
+ ...(options.dev && { customUrl: "http://localhost:5090" })
55
+ });
56
+ // Cargar instrucciones actuales
57
+ const loadSpinner = (0, ui_1.createSpinner)('Cargando...');
58
+ loadSpinner.start();
59
+ const agentData = await agent.getAgentById({ id: agentId });
60
+ loadSpinner.stop();
61
+ const current = agentData.instructions || {};
62
+ console.log((0, ui_1.section)('Instrucciones - ' + (agentData.name || agentId)));
63
+ const answers = await inquirer_1.default.prompt([
64
+ { type: 'list', name: 'tone', message: 'Tono:', choices: ['profesional', 'amigable', 'formal', 'casual', 'tecnico', 'empatico'], default: current.tone || 'profesional' },
65
+ { type: 'list', name: 'style', message: 'Estilo:', choices: ['conciso', 'detallado', 'conversacional', 'directo'], default: current.style || 'conciso' },
66
+ { type: 'input', name: 'personality', message: 'Personalidad:', default: current.personality || '' },
67
+ { type: 'input', name: 'objective', message: 'Objetivo:', default: current.objective || '' },
68
+ { type: 'list', name: 'language', message: 'Idioma:', choices: ['Espanol', 'English', 'Portugues'], default: current.language || 'Espanol' },
69
+ { type: 'confirm', name: 'emojis', message: 'Usar emojis?', default: current.emojis === true },
70
+ ]);
71
+ const instructions = {
72
+ ...current,
73
+ tone: answers.tone,
74
+ style: answers.style,
75
+ personality: answers.personality,
76
+ objective: answers.objective,
77
+ language: answers.language,
78
+ emojis: answers.emojis,
79
+ };
80
+ const spinner = (0, ui_1.createSpinner)('Guardando instrucciones...');
81
+ spinner.start();
82
+ await agent.setInstructions(agentId, instructions);
83
+ spinner.succeed('Instrucciones actualizadas');
84
+ }
85
+ catch (error) {
86
+ const message = error instanceof Error ? error.message : 'Error desconocido';
87
+ logger_1.logger.error(message);
88
+ process.exit(1);
89
+ }
90
+ });
91
+ // Set persona (wizard)
92
+ setGroup.command('persona')
93
+ .description('Configurar la persona del agente')
94
+ .argument('<agentId>', 'ID del agente')
95
+ .option('--dev', 'Usar ambiente de desarrollo', false)
96
+ .action(async (agentId, options) => {
97
+ try {
98
+ const credentials = await (0, credentials_1.getStoredCredentials)();
99
+ const agent = new plazbot_1.Agent({
100
+ workspaceId: credentials.workspace,
101
+ apiKey: credentials.apiKey,
102
+ zone: credentials.zone,
103
+ ...(options.dev && { customUrl: "http://localhost:5090" })
104
+ });
105
+ const loadSpinner = (0, ui_1.createSpinner)('Cargando...');
106
+ loadSpinner.start();
107
+ const agentData = await agent.getAgentById({ id: agentId });
108
+ loadSpinner.stop();
109
+ const current = agentData.person || {};
110
+ console.log((0, ui_1.section)('Persona - ' + (agentData.name || agentId)));
111
+ const answers = await inquirer_1.default.prompt([
112
+ { type: 'input', name: 'name', message: 'Nombre del personaje:', default: current.name || '' },
113
+ { type: 'input', name: 'role', message: 'Rol:', default: current.role || '' },
114
+ { type: 'confirm', name: 'speaksInFirstPerson', message: 'Hablar en primera persona?', default: current.speaksInFirstPerson !== false },
115
+ ]);
116
+ const spinner = (0, ui_1.createSpinner)('Guardando persona...');
117
+ spinner.start();
118
+ await agent.setPersona(agentId, answers);
119
+ spinner.succeed('Persona actualizada');
120
+ }
121
+ catch (error) {
122
+ const message = error instanceof Error ? error.message : 'Error desconocido';
123
+ logger_1.logger.error(message);
124
+ process.exit(1);
125
+ }
126
+ });
127
+ exports.setCommand = setGroup;