plazbot-cli 0.1.3 → 0.1.4
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.
- package/.claude/settings.local.json +14 -0
- package/CLAUDE.md +92 -0
- package/README.md +1 -1
- package/dist/cli.js +14 -5
- package/dist/commands/agent/ai-config.js +107 -0
- package/dist/commands/agent/chat.js +130 -34
- package/dist/commands/agent/copy.js +37 -0
- package/dist/commands/agent/create.js +80 -17
- package/dist/commands/agent/files.js +142 -0
- package/dist/commands/agent/index.js +14 -2
- package/dist/commands/agent/set.js +127 -0
- package/dist/commands/agent/templates.js +240 -0
- package/dist/commands/agent/tools.js +161 -0
- package/dist/commands/agent/wizard.js +369 -0
- package/dist/commands/whatsapp/broadcast.js +97 -0
- package/dist/commands/whatsapp/channels.js +86 -0
- package/dist/commands/whatsapp/chat.js +74 -0
- package/dist/commands/whatsapp/index.js +11 -2
- package/dist/commands/whatsapp/send-template.js +51 -14
- package/dist/commands/whatsapp/send.js +10 -10
- package/dist/commands/whatsapp/widget.js +64 -0
- package/dist/utils/banner.js +87 -0
- package/dist/utils/logger.js +27 -6
- package/dist/utils/ui.js +111 -0
- package/package.json +10 -2
- package/src/cli.ts +13 -5
- package/src/commands/agent/ai-config.ts +112 -0
- package/src/commands/agent/chat.ts +149 -40
- package/src/commands/agent/copy.ts +40 -0
- package/src/commands/agent/create.ts +58 -23
- package/src/commands/agent/files.ts +158 -0
- package/src/commands/agent/index.ts +14 -2
- package/src/commands/agent/set.ts +137 -0
- package/src/commands/agent/templates.ts +249 -0
- package/src/commands/agent/tools.ts +167 -0
- package/src/commands/agent/wizard.ts +475 -0
- package/src/commands/whatsapp/broadcast.ts +100 -0
- package/src/commands/whatsapp/channels.ts +98 -0
- package/src/commands/whatsapp/chat.ts +77 -0
- package/src/commands/whatsapp/index.ts +11 -2
- package/src/commands/whatsapp/send-template.ts +57 -19
- package/src/commands/whatsapp/send.ts +15 -14
- package/src/commands/whatsapp/widget.ts +67 -0
- package/src/utils/banner.ts +94 -0
- package/src/utils/logger.ts +26 -7
- package/src/utils/ui.ts +109 -0
- package/dist/commands/message/delete-webhook.js +0 -39
- package/dist/commands/message/index.js +0 -14
- package/dist/commands/message/register-webhook.js +0 -42
- package/dist/commands/message/send-template.js +0 -42
- package/dist/commands/message/send.js +0 -42
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(tree:*)",
|
|
5
|
+
"Bash(wc:*)",
|
|
6
|
+
"Bash(git -C /Users/kristian/Source/plazbot-v2/Plazbot-CLI-v2.0 log --oneline -10)",
|
|
7
|
+
"Bash(grep:*)",
|
|
8
|
+
"Bash(npm install:*)",
|
|
9
|
+
"Bash(npm run build:*)",
|
|
10
|
+
"Bash(node /Users/kristian/Source/plazbot-v2/Plazbot-CLI-v2.0/dist/cli.js:*)",
|
|
11
|
+
"Bash(npm ls:*)"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Descripción del Proyecto
|
|
6
|
+
|
|
7
|
+
Plazbot CLI v2.0 es una interfaz de línea de comandos oficial para la plataforma Plazbot. Permite gestionar agentes de IA, portales web y comunicaciones vía WhatsApp desde la terminal.
|
|
8
|
+
|
|
9
|
+
- **Lenguaje**: TypeScript 5.0+
|
|
10
|
+
- **Runtime**: Node.js >=16.0.0
|
|
11
|
+
- **Framework CLI**: Commander.js
|
|
12
|
+
|
|
13
|
+
## Comandos de Desarrollo
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Compilar TypeScript
|
|
17
|
+
npm run build
|
|
18
|
+
|
|
19
|
+
# Modo watch (compilación continua)
|
|
20
|
+
npm run dev
|
|
21
|
+
|
|
22
|
+
# Ejecutar CLI localmente
|
|
23
|
+
npm start
|
|
24
|
+
# o directamente:
|
|
25
|
+
node dist/cli.js
|
|
26
|
+
|
|
27
|
+
# Versionado
|
|
28
|
+
npm run version:patch # Incrementar patch
|
|
29
|
+
npm run version:minor # Incrementar minor
|
|
30
|
+
npm run version:major # Incrementar major
|
|
31
|
+
|
|
32
|
+
# SDK local vs npm
|
|
33
|
+
npm run prepare:dev # Usar SDK local (desarrollo)
|
|
34
|
+
npm run prepare:prod # Usar SDK de npm
|
|
35
|
+
|
|
36
|
+
# Publicación
|
|
37
|
+
npm run publish:beta # Publicar beta
|
|
38
|
+
npm run publish:prod # Publicar producción
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Arquitectura
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
src/
|
|
45
|
+
├── cli.ts # Entry point - registra todos los comandos
|
|
46
|
+
├── commands/ # Comandos organizados por dominio
|
|
47
|
+
│ ├── agent/ # CRUD + chat interactivo de agentes
|
|
48
|
+
│ ├── auth/ # init (login) y logout
|
|
49
|
+
│ ├── portal/ # CRUD + gestión de enlaces
|
|
50
|
+
│ └── whatsapp/ # Mensajes y webhooks
|
|
51
|
+
├── types/ # Interfaces TypeScript
|
|
52
|
+
└── utils/
|
|
53
|
+
├── logger.ts # Logging formateado (info, success, warning, error)
|
|
54
|
+
└── credentials.ts # Persistencia en ~/.plazbot/config.json
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Flujo de Comandos
|
|
58
|
+
|
|
59
|
+
1. `cli.ts` usa Commander.js para registrar grupos de comandos
|
|
60
|
+
2. Cada comando carga credenciales de `~/.plazbot/config.json`
|
|
61
|
+
3. Instancia el SDK (`plazbot`) con las credenciales
|
|
62
|
+
4. Ejecuta la operación contra el backend de Plazbot
|
|
63
|
+
5. Formatea la respuesta usando `logger.ts`
|
|
64
|
+
|
|
65
|
+
### SDK de Plazbot
|
|
66
|
+
|
|
67
|
+
El CLI depende del paquete `plazbot` que expone tres clases principales:
|
|
68
|
+
- **Agent** - Operaciones con agentes de IA
|
|
69
|
+
- **Portal** - Gestión de portales web
|
|
70
|
+
- **Message** - Envío de mensajes WhatsApp
|
|
71
|
+
|
|
72
|
+
### Credenciales
|
|
73
|
+
|
|
74
|
+
Se almacenan en `~/.plazbot/config.json`:
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"email": "string",
|
|
78
|
+
"apiKey": "string",
|
|
79
|
+
"workspace": "string",
|
|
80
|
+
"zone": "LA | EU"
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Flag --dev
|
|
85
|
+
|
|
86
|
+
Todos los comandos soportan `--dev` para apuntar al backend local (`http://localhost:5090`).
|
|
87
|
+
|
|
88
|
+
## Convenciones
|
|
89
|
+
|
|
90
|
+
- Cada grupo de comandos tiene un `index.ts` que exporta el comando padre con subcomandos
|
|
91
|
+
- Los tipos de opciones de comando se definen en `src/types/`
|
|
92
|
+
- El logger proporciona formato consistente: `logger.info()`, `logger.success()`, `logger.error()`
|
package/README.md
CHANGED
|
@@ -99,4 +99,4 @@ plazbot whatsapp delete-webhook
|
|
|
99
99
|
|
|
100
100
|
## Support
|
|
101
101
|
|
|
102
|
-
For
|
|
102
|
+
For more documentation, please visit our [Documentation](https://docs.plazbot.com) or contact support@plazbot.com
|
package/dist/cli.js
CHANGED
|
@@ -6,12 +6,13 @@ const portal_1 = require("./commands/portal");
|
|
|
6
6
|
const auth_1 = require("./commands/auth");
|
|
7
7
|
const agent_1 = require("./commands/agent");
|
|
8
8
|
const whatsapp_1 = require("./commands/whatsapp");
|
|
9
|
-
|
|
9
|
+
const banner_1 = require("./utils/banner");
|
|
10
|
+
// Configuracion basica del CLI
|
|
10
11
|
commander_1.program
|
|
11
12
|
.name('plazbot')
|
|
12
|
-
.description('CLI para
|
|
13
|
-
.version('0.
|
|
14
|
-
// Registrar todos los comandos de
|
|
13
|
+
.description('CLI oficial de Plazbot - Agentes de IA para WhatsApp, portales y desarrolladores')
|
|
14
|
+
.version('0.2.0');
|
|
15
|
+
// Registrar todos los comandos de autenticacion
|
|
15
16
|
auth_1.authCommands.forEach(cmd => commander_1.program.addCommand(cmd));
|
|
16
17
|
// Registrar todos los comandos de agente
|
|
17
18
|
commander_1.program.addCommand(agent_1.agentCommands);
|
|
@@ -19,4 +20,12 @@ commander_1.program.addCommand(agent_1.agentCommands);
|
|
|
19
20
|
commander_1.program.addCommand(portal_1.portalCommands);
|
|
20
21
|
// Registrar todos los comandos de WhatsApp
|
|
21
22
|
commander_1.program.addCommand(whatsapp_1.whatsappCommands);
|
|
22
|
-
|
|
23
|
+
// Si no se pasan argumentos, mostrar banner
|
|
24
|
+
if (process.argv.length <= 2) {
|
|
25
|
+
(0, banner_1.showBanner)().then(() => {
|
|
26
|
+
commander_1.program.outputHelp();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
commander_1.program.parse(process.argv);
|
|
31
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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.aiConfigCommand = 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 MODELS = {
|
|
14
|
+
openai: ['gpt-4o', 'gpt-4', 'gpt-3.5-turbo', 'o1-preview', 'o1-mini'],
|
|
15
|
+
claude: ['claude-3-5-sonnet-20241022', 'claude-3-opus-20240229', 'claude-3-haiku-20240307'],
|
|
16
|
+
gemini: ['gemini-2.0-flash', 'gemini-1.5-pro', 'gemini-1.5-flash'],
|
|
17
|
+
};
|
|
18
|
+
exports.aiConfigCommand = new commander_1.Command('ai-config')
|
|
19
|
+
.description('Configurar proveedor de IA del agente')
|
|
20
|
+
.argument('<agentId>', 'ID del agente')
|
|
21
|
+
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
22
|
+
.action(async (agentId, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
25
|
+
const agent = new plazbot_1.Agent({
|
|
26
|
+
workspaceId: credentials.workspace,
|
|
27
|
+
apiKey: credentials.apiKey,
|
|
28
|
+
zone: credentials.zone,
|
|
29
|
+
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
30
|
+
});
|
|
31
|
+
const spinner = (0, ui_1.createSpinner)('Cargando agente...');
|
|
32
|
+
spinner.start();
|
|
33
|
+
const agentData = await agent.getAgentById({ id: agentId });
|
|
34
|
+
spinner.stop();
|
|
35
|
+
console.log((0, ui_1.section)('Configuracion de IA - ' + (agentData.name || agentId)));
|
|
36
|
+
const currentProviders = agentData.aiProviders || [];
|
|
37
|
+
if (currentProviders.length > 0 && agentData.customAIConfig) {
|
|
38
|
+
console.log(ui_1.theme.bold('\n Configuracion actual:'));
|
|
39
|
+
currentProviders.forEach((p) => {
|
|
40
|
+
console.log((0, ui_1.kvPair)(' Proveedor', p.provider));
|
|
41
|
+
console.log((0, ui_1.kvPair)(' Modelo', p.model));
|
|
42
|
+
console.log((0, ui_1.kvPair)(' Temperatura', String(p.temperature)));
|
|
43
|
+
console.log((0, ui_1.kvPair)(' Max Tokens', String(p.maxTokens)));
|
|
44
|
+
console.log((0, ui_1.kvPair)(' Default', p.isDefault ? 'Si' : 'No'));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(ui_1.theme.muted('\n Usando configuracion de IA por defecto (Plazbot)'));
|
|
49
|
+
}
|
|
50
|
+
const { action } = await inquirer_1.default.prompt([{
|
|
51
|
+
type: 'list',
|
|
52
|
+
name: 'action',
|
|
53
|
+
message: 'Que deseas hacer?',
|
|
54
|
+
choices: [
|
|
55
|
+
{ name: 'Configurar nuevo proveedor', value: 'set' },
|
|
56
|
+
{ name: 'Usar configuracion por defecto', value: 'reset' },
|
|
57
|
+
{ name: 'Salir', value: 'exit' },
|
|
58
|
+
],
|
|
59
|
+
}]);
|
|
60
|
+
if (action === 'exit')
|
|
61
|
+
return;
|
|
62
|
+
if (action === 'reset') {
|
|
63
|
+
const resetConfig = { ...agentData, customAIConfig: false, aiProviders: [] };
|
|
64
|
+
delete resetConfig.id;
|
|
65
|
+
delete resetConfig._id;
|
|
66
|
+
const resetSpinner = (0, ui_1.createSpinner)('Reseteando configuracion...');
|
|
67
|
+
resetSpinner.start();
|
|
68
|
+
await agent.updateAgent(agentId, resetConfig);
|
|
69
|
+
resetSpinner.succeed('Usando configuracion por defecto');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Configurar nuevo proveedor
|
|
73
|
+
const ai = await inquirer_1.default.prompt([
|
|
74
|
+
{ type: 'list', name: 'provider', message: 'Proveedor:', choices: ['openai', 'claude', 'gemini'] },
|
|
75
|
+
]);
|
|
76
|
+
const models = MODELS[ai.provider] || MODELS.openai;
|
|
77
|
+
const config = await inquirer_1.default.prompt([
|
|
78
|
+
{ type: 'list', name: 'model', message: 'Modelo:', choices: models },
|
|
79
|
+
{ type: 'password', name: 'apiToken', message: 'API Token:', mask: '*', validate: (v) => v.length > 0 || 'Requerido' },
|
|
80
|
+
{ type: 'number', name: 'temperature', message: 'Temperatura (0-2):', default: 0.7 },
|
|
81
|
+
{ type: 'number', name: 'maxTokens', message: 'Max tokens (1024-16384):', default: 4096 },
|
|
82
|
+
]);
|
|
83
|
+
const updatedConfig = {
|
|
84
|
+
...agentData,
|
|
85
|
+
customAIConfig: true,
|
|
86
|
+
aiProviders: [{
|
|
87
|
+
provider: ai.provider,
|
|
88
|
+
model: config.model,
|
|
89
|
+
apiToken: config.apiToken,
|
|
90
|
+
temperature: config.temperature,
|
|
91
|
+
maxTokens: config.maxTokens,
|
|
92
|
+
isDefault: true,
|
|
93
|
+
}],
|
|
94
|
+
};
|
|
95
|
+
delete updatedConfig.id;
|
|
96
|
+
delete updatedConfig._id;
|
|
97
|
+
const updateSpinner = (0, ui_1.createSpinner)('Guardando configuracion...');
|
|
98
|
+
updateSpinner.start();
|
|
99
|
+
await agent.updateAgent(agentId, updatedConfig);
|
|
100
|
+
updateSpinner.succeed(`Proveedor configurado: ${ai.provider} / ${config.model}`);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const message = error instanceof Error ? error.message : 'Error desconocido';
|
|
104
|
+
logger_1.logger.error(message);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
@@ -7,17 +7,27 @@ exports.chatCommand = void 0;
|
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
8
|
const plazbot_1 = require("plazbot");
|
|
9
9
|
const credentials_1 = require("../../utils/credentials");
|
|
10
|
+
const logger_1 = require("../../utils/logger");
|
|
11
|
+
const ui_1 = require("../../utils/ui");
|
|
10
12
|
const crypto_1 = __importDefault(require("crypto"));
|
|
11
13
|
const readline_1 = __importDefault(require("readline"));
|
|
14
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
+
const COMMANDS_HELP = `
|
|
16
|
+
${chalk_1.default.bold('Comandos disponibles:')}
|
|
17
|
+
${chalk_1.default.hex('#4CAF50')('/exit')} Terminar conversacion
|
|
18
|
+
${chalk_1.default.hex('#4CAF50')('/clear')} Limpiar pantalla
|
|
19
|
+
${chalk_1.default.hex('#4CAF50')('/info')} Informacion de la sesion
|
|
20
|
+
${chalk_1.default.hex('#4CAF50')('/sources')} Mostrar/ocultar fuentes
|
|
21
|
+
${chalk_1.default.hex('#4CAF50')('/help')} Mostrar estos comandos
|
|
22
|
+
`;
|
|
12
23
|
exports.chatCommand = new commander_1.Command('chat')
|
|
13
|
-
.description('Inicia una
|
|
24
|
+
.description('Inicia una sesion de chat interactiva con un agente')
|
|
14
25
|
.requiredOption('-a, --agent-id <id>', 'ID del agente')
|
|
15
|
-
.option('-s, --session-id <id>', 'ID de
|
|
16
|
-
.option('-m, --multiple-answers', 'Permitir
|
|
26
|
+
.option('-s, --session-id <id>', 'ID de sesion (opcional)')
|
|
27
|
+
.option('-m, --multiple-answers', 'Permitir multiples respuestas', false)
|
|
17
28
|
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
18
29
|
.action(async (options) => {
|
|
19
30
|
try {
|
|
20
|
-
// Obtener credenciales guardadas
|
|
21
31
|
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
22
32
|
const agent = new plazbot_1.Agent({
|
|
23
33
|
workspaceId: credentials.workspace,
|
|
@@ -25,68 +35,154 @@ exports.chatCommand = new commander_1.Command('chat')
|
|
|
25
35
|
zone: credentials.zone,
|
|
26
36
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
27
37
|
});
|
|
28
|
-
// Generar un sessionId si no se proporcionó uno
|
|
29
38
|
const sessionId = options.sessionId || crypto_1.default.randomUUID();
|
|
30
|
-
|
|
39
|
+
let showSources = true;
|
|
40
|
+
// Cargar info del agente
|
|
41
|
+
let agentInfo = null;
|
|
42
|
+
try {
|
|
43
|
+
process.stdout.write(chalk_1.default.gray(' Conectando con agente...'));
|
|
44
|
+
agentInfo = await agent.getAgentById({ id: options.agentId });
|
|
45
|
+
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
49
|
+
}
|
|
31
50
|
const rl = readline_1.default.createInterface({
|
|
32
51
|
input: process.stdin,
|
|
33
52
|
output: process.stdout
|
|
34
53
|
});
|
|
35
|
-
//
|
|
54
|
+
// Pantalla de chat
|
|
36
55
|
console.clear();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log(
|
|
40
|
-
console.log('
|
|
41
|
-
console.log('│' +
|
|
42
|
-
console.log('│' +
|
|
43
|
-
console.log('│' + '
|
|
44
|
-
console.log('└' + '─'.repeat(
|
|
45
|
-
console.log(
|
|
46
|
-
//
|
|
56
|
+
const agentName = agentInfo?.name || 'Agente';
|
|
57
|
+
const toolCalling = agentInfo?.useToolCalling ? chalk_1.default.hex('#4CAF50')(' [Tool Calling]') : '';
|
|
58
|
+
console.log();
|
|
59
|
+
console.log(chalk_1.default.hex('#4CAF50')(' ┌' + '─'.repeat(58) + '┐'));
|
|
60
|
+
console.log(chalk_1.default.hex('#4CAF50')(' │') + chalk_1.default.bold(` ${agentName}${toolCalling}`).padEnd(68) + chalk_1.default.hex('#4CAF50')('│'));
|
|
61
|
+
console.log(chalk_1.default.hex('#4CAF50')(' │') + chalk_1.default.gray(` Session: ${sessionId.substring(0, 8)}...`).padEnd(68) + chalk_1.default.hex('#4CAF50')('│'));
|
|
62
|
+
console.log(chalk_1.default.hex('#4CAF50')(' │') + chalk_1.default.gray(' /help para ver comandos').padEnd(68) + chalk_1.default.hex('#4CAF50')('│'));
|
|
63
|
+
console.log(chalk_1.default.hex('#4CAF50')(' └' + '─'.repeat(58) + '┘'));
|
|
64
|
+
console.log();
|
|
65
|
+
// Saludo del agente
|
|
66
|
+
if (agentInfo?.instructions?.greeting) {
|
|
67
|
+
const timestamp = new Date().toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit' });
|
|
68
|
+
console.log(chalk_1.default.hex('#4CAF50')(` ${agentName}`) + chalk_1.default.gray(` ${timestamp}`));
|
|
69
|
+
console.log(chalk_1.default.white(` ${agentInfo.instructions.greeting}`));
|
|
70
|
+
console.log();
|
|
71
|
+
}
|
|
47
72
|
const askQuestion = () => {
|
|
48
|
-
rl.question('
|
|
73
|
+
rl.question(chalk_1.default.hex('#2196F3')(' Tu > '), async (question) => {
|
|
74
|
+
if (!question.trim()) {
|
|
75
|
+
askQuestion();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Comandos especiales
|
|
49
79
|
if (question.toLowerCase() === '/exit') {
|
|
50
|
-
console.log('\
|
|
80
|
+
console.log(chalk_1.default.gray('\n Sesion terminada.\n'));
|
|
51
81
|
rl.close();
|
|
52
82
|
return;
|
|
53
83
|
}
|
|
84
|
+
if (question.toLowerCase() === '/clear') {
|
|
85
|
+
console.clear();
|
|
86
|
+
askQuestion();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (question.toLowerCase() === '/help') {
|
|
90
|
+
console.log(COMMANDS_HELP);
|
|
91
|
+
askQuestion();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (question.toLowerCase() === '/info') {
|
|
95
|
+
console.log((0, ui_1.section)('Informacion de sesion'));
|
|
96
|
+
logger_1.logger.label('Agent ID', options.agentId);
|
|
97
|
+
logger_1.logger.label('Session ID', sessionId);
|
|
98
|
+
logger_1.logger.label('Agente', agentName);
|
|
99
|
+
logger_1.logger.label('Tool Calling', agentInfo?.useToolCalling ? 'Activado' : 'Desactivado');
|
|
100
|
+
logger_1.logger.label('AI Provider', agentInfo?.customAIConfig ? (agentInfo.aiProviders?.[0]?.provider || 'Custom') : 'Default');
|
|
101
|
+
console.log();
|
|
102
|
+
askQuestion();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (question.toLowerCase() === '/sources') {
|
|
106
|
+
showSources = !showSources;
|
|
107
|
+
console.log(chalk_1.default.gray(` Fuentes: ${showSources ? 'activadas' : 'desactivadas'}`));
|
|
108
|
+
console.log();
|
|
109
|
+
askQuestion();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
54
112
|
try {
|
|
55
|
-
|
|
113
|
+
process.stdout.write(chalk_1.default.gray(' ...pensando\n'));
|
|
56
114
|
const response = await agent.onMessage({
|
|
57
115
|
agentId: options.agentId,
|
|
58
116
|
question,
|
|
59
117
|
sessionId,
|
|
60
118
|
multipleAnswers: options.multipleAnswers
|
|
61
119
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
120
|
+
const timestamp = new Date().toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit' });
|
|
121
|
+
// Mostrar tool calls si hay
|
|
122
|
+
if (response.actionsExecuted && response.actionsExecuted.length > 0) {
|
|
123
|
+
response.actionsExecuted.forEach((action) => {
|
|
124
|
+
console.log(chalk_1.default.hex('#FFA726')(` ⚡ Tool: ${action.name || action.intent || 'action'}`));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// Respuesta del agente
|
|
128
|
+
console.log();
|
|
129
|
+
console.log(chalk_1.default.hex('#4CAF50')(` ${agentName}`) + chalk_1.default.gray(` ${timestamp}`));
|
|
130
|
+
// Formatear respuesta (soporte basico de markdown)
|
|
131
|
+
const formattedAnswer = formatResponse(response.answer);
|
|
132
|
+
console.log(formattedAnswer);
|
|
133
|
+
console.log();
|
|
134
|
+
// Fuentes
|
|
135
|
+
if (showSources && response.sources && response.sources.length > 0) {
|
|
136
|
+
console.log(chalk_1.default.gray(' Fuentes:'));
|
|
68
137
|
response.sources.forEach((source) => {
|
|
69
|
-
console.log(`
|
|
138
|
+
console.log(chalk_1.default.gray(` - ${source.title || 'Sin titulo'}`));
|
|
70
139
|
if (source.url)
|
|
71
|
-
console.log(`
|
|
140
|
+
console.log(chalk_1.default.gray(` ${source.url}`));
|
|
72
141
|
});
|
|
73
|
-
console.log();
|
|
142
|
+
console.log();
|
|
74
143
|
}
|
|
75
|
-
askQuestion();
|
|
144
|
+
askQuestion();
|
|
76
145
|
}
|
|
77
146
|
catch (error) {
|
|
78
147
|
const message = error instanceof Error ? error.message : 'Error desconocido';
|
|
79
|
-
console.
|
|
80
|
-
askQuestion();
|
|
148
|
+
console.log(chalk_1.default.hex('#EF5350')(`\n ✖ Error: ${message}\n`));
|
|
149
|
+
askQuestion();
|
|
81
150
|
}
|
|
82
151
|
});
|
|
83
152
|
};
|
|
84
|
-
// Iniciar el ciclo de preguntas
|
|
85
153
|
askQuestion();
|
|
86
154
|
}
|
|
87
155
|
catch (error) {
|
|
88
156
|
const message = error instanceof Error ? error.message : 'Error desconocido';
|
|
89
|
-
|
|
157
|
+
logger_1.logger.error(message);
|
|
90
158
|
process.exit(1);
|
|
91
159
|
}
|
|
92
160
|
});
|
|
161
|
+
function formatResponse(text) {
|
|
162
|
+
if (!text)
|
|
163
|
+
return '';
|
|
164
|
+
return text.split('\n').map(line => {
|
|
165
|
+
// Headers
|
|
166
|
+
if (line.startsWith('### '))
|
|
167
|
+
return chalk_1.default.bold.hex('#4CAF50')(' ' + line.substring(4));
|
|
168
|
+
if (line.startsWith('## '))
|
|
169
|
+
return chalk_1.default.bold.hex('#4CAF50')(' ' + line.substring(3));
|
|
170
|
+
if (line.startsWith('# '))
|
|
171
|
+
return chalk_1.default.bold.hex('#4CAF50')(' ' + line.substring(2));
|
|
172
|
+
// Bold
|
|
173
|
+
line = line.replace(/\*\*(.*?)\*\*/g, (_, text) => chalk_1.default.bold(text));
|
|
174
|
+
// Italic
|
|
175
|
+
line = line.replace(/\*(.*?)\*/g, (_, text) => chalk_1.default.italic(text));
|
|
176
|
+
// Code inline
|
|
177
|
+
line = line.replace(/`(.*?)`/g, (_, text) => chalk_1.default.hex('#FFA726')(text));
|
|
178
|
+
// List items
|
|
179
|
+
if (line.match(/^\s*[-*]\s/)) {
|
|
180
|
+
return chalk_1.default.white(' ' + line.replace(/^\s*[-*]\s/, ' • '));
|
|
181
|
+
}
|
|
182
|
+
// Numbered lists
|
|
183
|
+
if (line.match(/^\s*\d+\.\s/)) {
|
|
184
|
+
return chalk_1.default.white(' ' + line);
|
|
185
|
+
}
|
|
186
|
+
return chalk_1.default.white(' ' + line);
|
|
187
|
+
}).join('\n');
|
|
188
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyCommand = 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
|
+
exports.copyCommand = new commander_1.Command('copy')
|
|
10
|
+
.description('Clonar un agente existente')
|
|
11
|
+
.argument('<agentId>', 'ID del agente a clonar')
|
|
12
|
+
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
13
|
+
.action(async (agentId, options) => {
|
|
14
|
+
try {
|
|
15
|
+
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
16
|
+
const agent = new plazbot_1.Agent({
|
|
17
|
+
workspaceId: credentials.workspace,
|
|
18
|
+
apiKey: credentials.apiKey,
|
|
19
|
+
zone: credentials.zone,
|
|
20
|
+
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
21
|
+
});
|
|
22
|
+
const spinner = (0, ui_1.createSpinner)('Clonando agente...');
|
|
23
|
+
spinner.start();
|
|
24
|
+
const result = await agent.copyAgent({ id: agentId });
|
|
25
|
+
spinner.succeed('Agente clonado exitosamente');
|
|
26
|
+
logger_1.logger.title('Agente clonado');
|
|
27
|
+
if (result?.agentId || result?.id) {
|
|
28
|
+
logger_1.logger.label('Nuevo ID', result.agentId || result.id);
|
|
29
|
+
}
|
|
30
|
+
logger_1.logger.dim('\nEl agente clonado tiene el widget deshabilitado por defecto.');
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const message = error instanceof Error ? error.message : 'Error desconocido';
|
|
34
|
+
logger_1.logger.error(message);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -8,14 +41,15 @@ const commander_1 = require("commander");
|
|
|
8
41
|
const plazbot_1 = require("plazbot");
|
|
9
42
|
const credentials_1 = require("../../utils/credentials");
|
|
10
43
|
const logger_1 = require("../../utils/logger");
|
|
44
|
+
const ui_1 = require("../../utils/ui");
|
|
45
|
+
const wizard_1 = require("./wizard");
|
|
11
46
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
12
47
|
exports.createCommand = new commander_1.Command('create')
|
|
13
|
-
.description('Crea un nuevo agente
|
|
14
|
-
.argument('
|
|
48
|
+
.description('Crea un nuevo agente de IA (wizard interactivo o archivo JSON)')
|
|
49
|
+
.argument('[configPath]', 'Ruta al archivo de configuracion JSON (opcional)')
|
|
15
50
|
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
16
51
|
.action(async (configPath, options) => {
|
|
17
52
|
try {
|
|
18
|
-
// Obtener credenciales guardadas
|
|
19
53
|
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
20
54
|
const agent = new plazbot_1.Agent({
|
|
21
55
|
workspaceId: credentials.workspace,
|
|
@@ -23,25 +57,54 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
23
57
|
zone: credentials.zone,
|
|
24
58
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
25
59
|
});
|
|
26
|
-
// Leer archivo de configuración
|
|
27
60
|
let agentConfig;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
if (configPath) {
|
|
62
|
+
// Modo archivo: leer JSON
|
|
63
|
+
try {
|
|
64
|
+
const fileContent = await promises_1.default.readFile(configPath, 'utf-8');
|
|
65
|
+
agentConfig = JSON.parse(fileContent);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const errorMessage = error instanceof Error ? error.message : 'Error desconocido';
|
|
69
|
+
throw new Error(`Error al leer el archivo de configuracion: ${errorMessage}`);
|
|
70
|
+
}
|
|
71
|
+
logger_1.logger.title('Creando agente desde archivo');
|
|
72
|
+
logger_1.logger.json(agentConfig);
|
|
31
73
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
74
|
+
else {
|
|
75
|
+
// Modo wizard interactivo
|
|
76
|
+
agentConfig = await (0, wizard_1.runAgentWizard)(credentials.zone);
|
|
77
|
+
const inquirer = await Promise.resolve().then(() => __importStar(require('inquirer')));
|
|
78
|
+
const { confirm } = await inquirer.default.prompt([{
|
|
79
|
+
type: 'confirm',
|
|
80
|
+
name: 'confirm',
|
|
81
|
+
message: 'Crear el agente con esta configuracion?',
|
|
82
|
+
default: true,
|
|
83
|
+
}]);
|
|
84
|
+
if (!confirm) {
|
|
85
|
+
logger_1.logger.warning('Creacion cancelada');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
35
88
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
logger_1.logger.info(JSON.stringify(agentConfig, null, 2));
|
|
89
|
+
const spinner = (0, ui_1.createSpinner)('Creando agente...');
|
|
90
|
+
spinner.start();
|
|
39
91
|
const result = await agent.addAgent(agentConfig);
|
|
40
|
-
|
|
41
|
-
logger_1.logger.
|
|
42
|
-
|
|
92
|
+
spinner.succeed('Agente creado exitosamente');
|
|
93
|
+
logger_1.logger.title('Detalles del agente');
|
|
94
|
+
if (result.agentId) {
|
|
95
|
+
logger_1.logger.label('ID', result.agentId);
|
|
96
|
+
}
|
|
97
|
+
if (agentConfig.name) {
|
|
98
|
+
logger_1.logger.label('Nombre', agentConfig.name);
|
|
99
|
+
}
|
|
100
|
+
logger_1.logger.label('Tool Calling', agentConfig.useToolCalling ? 'Activado' : 'Desactivado');
|
|
101
|
+
if (agentConfig.channels && agentConfig.channels.length > 0) {
|
|
102
|
+
logger_1.logger.label('WhatsApp', agentConfig.channels[0].key);
|
|
103
|
+
}
|
|
104
|
+
console.log();
|
|
105
|
+
logger_1.logger.dim('Siguiente paso: plazbot agent chat -a ' + (result.agentId || '<agentId>'));
|
|
43
106
|
if (options.dev) {
|
|
44
|
-
logger_1.logger.warning('
|
|
107
|
+
logger_1.logger.warning('Ambiente: desarrollo');
|
|
45
108
|
}
|
|
46
109
|
}
|
|
47
110
|
catch (error) {
|