plazbot-cli 0.2.2 → 0.2.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/dist/commands/agent/chat.js +1 -1
- package/dist/commands/agent/delete.js +1 -1
- package/dist/commands/agent/enable-widget.js +7 -11
- package/dist/commands/agent/get.js +1 -1
- package/dist/commands/agent/index.js +3 -1
- package/dist/commands/agent/list.js +1 -1
- package/dist/commands/agent/monitor.js +293 -0
- package/dist/commands/agent/on-message.js +10 -12
- package/dist/commands/agent/update.js +1 -1
- package/dist/commands/auth/login.js +13 -12
- package/dist/commands/portal/add-agent.js +5 -10
- package/dist/commands/portal/add-link.js +3 -2
- package/dist/commands/portal/clear-links.js +3 -2
- package/dist/commands/portal/create.js +3 -7
- package/dist/commands/portal/delete.js +5 -6
- package/dist/commands/portal/get.js +15 -17
- package/dist/commands/portal/list.js +15 -17
- package/dist/commands/portal/update.js +5 -6
- package/dist/commands/whatsapp/delete-webhook.js +3 -3
- package/dist/commands/whatsapp/register-webhook.js +4 -4
- package/dist/utils/logger.js +3 -3
- package/package.json +2 -1
- package/src/commands/agent/chat.ts +1 -1
- package/src/commands/agent/delete.ts +1 -1
- package/src/commands/agent/enable-widget.ts +8 -12
- package/src/commands/agent/get.ts +1 -1
- package/src/commands/agent/index.ts +3 -1
- package/src/commands/agent/list.ts +1 -1
- package/src/commands/agent/monitor.ts +346 -0
- package/src/commands/agent/on-message.ts +11 -13
- package/src/commands/agent/update.ts +1 -1
- package/src/commands/auth/login.ts +13 -12
- package/src/commands/portal/add-agent.ts +5 -11
- package/src/commands/portal/add-link.ts +2 -2
- package/src/commands/portal/clear-links.ts +3 -2
- package/src/commands/portal/create.ts +3 -8
- package/src/commands/portal/delete.ts +5 -6
- package/src/commands/portal/get.ts +16 -20
- package/src/commands/portal/list.ts +16 -19
- package/src/commands/portal/update.ts +5 -6
- package/src/commands/whatsapp/delete-webhook.ts +3 -3
- package/src/commands/whatsapp/register-webhook.ts +4 -4
- package/src/utils/logger.ts +3 -3
|
@@ -121,7 +121,7 @@ exports.chatCommand = new commander_1.Command('chat')
|
|
|
121
121
|
// Mostrar tool calls si hay
|
|
122
122
|
if (response.actionsExecuted && response.actionsExecuted.length > 0) {
|
|
123
123
|
response.actionsExecuted.forEach((action) => {
|
|
124
|
-
console.log(chalk_1.default.hex('#FFA726')(`
|
|
124
|
+
console.log(chalk_1.default.hex('#FFA726')(` Tool: ${action.name || action.intent || 'action'}`));
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
// Respuesta del agente
|
|
@@ -37,7 +37,7 @@ exports.deleteCommand = new commander_1.Command('delete')
|
|
|
37
37
|
output: process.stdout
|
|
38
38
|
});
|
|
39
39
|
// Preguntar por confirmación
|
|
40
|
-
rl.question('\
|
|
40
|
+
rl.question('\nEstas seguro que deseas eliminar este agente? (y/N): ', async (answer) => {
|
|
41
41
|
if (answer.toLowerCase() === 'y') {
|
|
42
42
|
await agent.deleteAgent({
|
|
43
43
|
id: agentId
|
|
@@ -22,10 +22,8 @@ exports.enableCommand = new commander_1.Command('enable-widget')
|
|
|
22
22
|
});
|
|
23
23
|
// Obtener estado actual del agente
|
|
24
24
|
const agentDetails = await agent.getAgentById({ id: agentId });
|
|
25
|
-
logger_1.logger.
|
|
26
|
-
logger_1.logger.
|
|
27
|
-
logger_1.logger.info(`Agente: ${agentDetails.name}`);
|
|
28
|
-
logger_1.logger.divider();
|
|
25
|
+
logger_1.logger.title('Estado actual del widget');
|
|
26
|
+
logger_1.logger.label('Agente', agentDetails.name);
|
|
29
27
|
// Cambiar estado
|
|
30
28
|
const newState = !options.disable; // Si --disable está presente, newState será false
|
|
31
29
|
const result = await agent.enableWidget({
|
|
@@ -33,14 +31,12 @@ exports.enableCommand = new commander_1.Command('enable-widget')
|
|
|
33
31
|
enable: newState
|
|
34
32
|
});
|
|
35
33
|
logger_1.logger.success(`Widget ${newState ? 'habilitado' : 'deshabilitado'} exitosamente`);
|
|
36
|
-
logger_1.logger.
|
|
37
|
-
logger_1.logger.
|
|
38
|
-
logger_1.logger.
|
|
39
|
-
logger_1.logger.info(`Mensaje: ${result.message}`);
|
|
34
|
+
logger_1.logger.title('Respuesta del servidor');
|
|
35
|
+
logger_1.logger.label('Estado', result.success ? 'Exitoso' : 'Fallido');
|
|
36
|
+
logger_1.logger.label('Mensaje', result.message);
|
|
40
37
|
if (newState && result.script) {
|
|
41
|
-
logger_1.logger.
|
|
42
|
-
logger_1.logger.
|
|
43
|
-
logger_1.logger.info('Coloca este script debajo de la etiqueta <HEAD> en tu sitio web:');
|
|
38
|
+
logger_1.logger.title('Instrucciones de instalacion');
|
|
39
|
+
logger_1.logger.dim('Coloca este script debajo de la etiqueta <HEAD> en tu sitio web:');
|
|
44
40
|
logger_1.logger.info('\n' + result.script);
|
|
45
41
|
}
|
|
46
42
|
if (options.dev) {
|
|
@@ -30,7 +30,7 @@ exports.getCommand = new commander_1.Command('get')
|
|
|
30
30
|
logger_1.logger.info(`ID: ${agentData.id}`);
|
|
31
31
|
logger_1.logger.info(`Nombre: ${agentData.name}`);
|
|
32
32
|
logger_1.logger.info(`Descripción: ${agentData.description}`);
|
|
33
|
-
logger_1.logger.info(`Estado: ${agentData.enable ? '
|
|
33
|
+
logger_1.logger.info(`Estado: ${agentData.enable ? 'Activo' : 'Inactivo'}`);
|
|
34
34
|
logger_1.logger.info(`Zona: ${agentData.zone}`);
|
|
35
35
|
logger_1.logger.info(`Buffer: ${agentData.buffer}`);
|
|
36
36
|
logger_1.logger.info(`Color: ${agentData.color}`);
|
|
@@ -16,6 +16,7 @@ const templates_1 = require("./templates");
|
|
|
16
16
|
const copy_1 = require("./copy");
|
|
17
17
|
const files_1 = require("./files");
|
|
18
18
|
const set_1 = require("./set");
|
|
19
|
+
const monitor_1 = require("./monitor");
|
|
19
20
|
exports.agentCommands = new commander_1.Command('agent')
|
|
20
21
|
.description('Comandos relacionados con agentes de IA')
|
|
21
22
|
.addCommand(list_1.listCommand)
|
|
@@ -31,4 +32,5 @@ exports.agentCommands = new commander_1.Command('agent')
|
|
|
31
32
|
.addCommand(templates_1.templatesCommand)
|
|
32
33
|
.addCommand(copy_1.copyCommand)
|
|
33
34
|
.addCommand(files_1.filesCommand)
|
|
34
|
-
.addCommand(set_1.setCommand)
|
|
35
|
+
.addCommand(set_1.setCommand)
|
|
36
|
+
.addCommand(monitor_1.monitorCommand);
|
|
@@ -30,7 +30,7 @@ exports.listCommand = new commander_1.Command('list')
|
|
|
30
30
|
agents.forEach((a, index) => {
|
|
31
31
|
logger_1.logger.info(`${index + 1}. ID: ${a.id}`);
|
|
32
32
|
logger_1.logger.info(` Nombre: ${a.name}`);
|
|
33
|
-
logger_1.logger.info(` Estado: ${a.enable ? '
|
|
33
|
+
logger_1.logger.info(` Estado: ${a.enable ? 'Activo' : 'Inactivo'}`);
|
|
34
34
|
logger_1.logger.info(` Descripción: ${a.description}`);
|
|
35
35
|
logger_1.logger.info(` Creado: ${a.createdAt ? new Date(a.createdAt).toLocaleString() : 'N/A'}`);
|
|
36
36
|
logger_1.logger.divider();
|
|
@@ -0,0 +1,293 @@
|
|
|
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.monitorCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const plazbot_1 = require("plazbot");
|
|
9
|
+
const credentials_1 = require("../../utils/credentials");
|
|
10
|
+
const logger_1 = require("../../utils/logger");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const readline_1 = __importDefault(require("readline"));
|
|
13
|
+
const signalr_1 = require("@microsoft/signalr");
|
|
14
|
+
// Colores por tipo de evento (mismos del MonitorTab frontend)
|
|
15
|
+
const EVENT_COLORS = {
|
|
16
|
+
msg_in: { color: '#22d3ee', label: 'msg_in' },
|
|
17
|
+
msg_out: { color: '#4ade80', label: 'msg_out' },
|
|
18
|
+
tool_call: { color: '#c084fc', label: 'tool_call' },
|
|
19
|
+
api_req: { color: '#fbbf24', label: 'api_req' },
|
|
20
|
+
api_res: { color: '#fbbf24', label: 'api_res' },
|
|
21
|
+
action: { color: '#f97316', label: 'action' },
|
|
22
|
+
rag: { color: '#60a5fa', label: 'rag' },
|
|
23
|
+
tokens: { color: '#94a3b8', label: 'tokens' },
|
|
24
|
+
error: { color: '#ef4444', label: 'error' },
|
|
25
|
+
model: { color: '#a78bfa', label: 'model' },
|
|
26
|
+
intent: { color: '#a78bfa', label: 'intent' },
|
|
27
|
+
bot_off: { color: '#f97316', label: 'bot_off' },
|
|
28
|
+
session_field: { color: '#a78bfa', label: 'session_field' },
|
|
29
|
+
};
|
|
30
|
+
const DEFAULT_EVENT_COLOR = { color: '#94a3b8', label: 'unknown' };
|
|
31
|
+
function getBaseUrl(zone, dev) {
|
|
32
|
+
if (dev)
|
|
33
|
+
return 'http://localhost:5090';
|
|
34
|
+
return zone === 'EU' ? 'https://apieu.plazbot.com' : 'https://api.plazbot.com';
|
|
35
|
+
}
|
|
36
|
+
function formatTimestamp(ts) {
|
|
37
|
+
try {
|
|
38
|
+
const d = new Date(ts);
|
|
39
|
+
return d.toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return ts.substring(11, 19);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function truncate(text, maxLen) {
|
|
46
|
+
if (!text)
|
|
47
|
+
return '';
|
|
48
|
+
return text.length > maxLen ? text.substring(0, maxLen - 3) + '...' : text;
|
|
49
|
+
}
|
|
50
|
+
function shortSession(sessionId) {
|
|
51
|
+
if (!sessionId)
|
|
52
|
+
return '';
|
|
53
|
+
return sessionId.substring(0, 6);
|
|
54
|
+
}
|
|
55
|
+
function renderLogLine(log, opts, lastSessionId) {
|
|
56
|
+
// Modo JSON crudo
|
|
57
|
+
if (opts.jsonMode) {
|
|
58
|
+
return JSON.stringify(log);
|
|
59
|
+
}
|
|
60
|
+
const config = EVENT_COLORS[log.event_type] || DEFAULT_EVENT_COLOR;
|
|
61
|
+
const colorFn = chalk_1.default.hex(config.color);
|
|
62
|
+
const grayFn = chalk_1.default.hex('#71717a');
|
|
63
|
+
const dimFn = chalk_1.default.hex('#52525b');
|
|
64
|
+
let lines = [];
|
|
65
|
+
// Separador de sesion
|
|
66
|
+
if (lastSessionId && log.session_id && log.session_id !== lastSessionId) {
|
|
67
|
+
lines.push(dimFn(' ' + '─'.repeat(16) + ' nueva sesion ' + '─'.repeat(16)));
|
|
68
|
+
}
|
|
69
|
+
// Linea principal
|
|
70
|
+
const timestamp = grayFn(formatTimestamp(log.timestamp));
|
|
71
|
+
const dot = colorFn('●');
|
|
72
|
+
const eventType = colorFn(config.label.padEnd(14));
|
|
73
|
+
const title = chalk_1.default.white(truncate(log.event_title, 80));
|
|
74
|
+
const duration = log.duration_ms > 0 ? dimFn(` ${log.duration_ms}ms`) : '';
|
|
75
|
+
const session = opts.showSession && log.session_id
|
|
76
|
+
? dimFn(` [${shortSession(log.session_id)}]`)
|
|
77
|
+
: '';
|
|
78
|
+
lines.push(` ${timestamp} ${dot} ${eventType} ${title}${duration}${session}`);
|
|
79
|
+
// Linea de contacto para mensajes
|
|
80
|
+
if (log.contact_name && (log.event_type === 'msg_in' || log.event_type === 'msg_out')) {
|
|
81
|
+
lines.push(dimFn(' | contacto: ') + dimFn(log.contact_name));
|
|
82
|
+
}
|
|
83
|
+
return lines.join('\n');
|
|
84
|
+
}
|
|
85
|
+
function printHeader(agentName) {
|
|
86
|
+
console.log();
|
|
87
|
+
console.log(chalk_1.default.hex('#4CAF50')(' ┌' + '─'.repeat(62) + '┐'));
|
|
88
|
+
console.log(chalk_1.default.hex('#4CAF50')(' │') +
|
|
89
|
+
chalk_1.default.bold(` Monitor`) +
|
|
90
|
+
chalk_1.default.hex('#4ade80')(' ● En vivo') +
|
|
91
|
+
' '.repeat(38) +
|
|
92
|
+
chalk_1.default.hex('#4CAF50')('│'));
|
|
93
|
+
console.log(chalk_1.default.hex('#4CAF50')(' │') +
|
|
94
|
+
chalk_1.default.gray(` Agente: ${truncate(agentName, 44)}`) +
|
|
95
|
+
' '.repeat(Math.max(0, 49 - agentName.length)) +
|
|
96
|
+
chalk_1.default.hex('#4CAF50')('│'));
|
|
97
|
+
console.log(chalk_1.default.hex('#4CAF50')(' │') +
|
|
98
|
+
chalk_1.default.gray(' Ctrl+C salir | /filter <tipo> | /clear | /help') +
|
|
99
|
+
' '.repeat(12) +
|
|
100
|
+
chalk_1.default.hex('#4CAF50')('│'));
|
|
101
|
+
console.log(chalk_1.default.hex('#4CAF50')(' └' + '─'.repeat(62) + '┘'));
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
const COMMANDS_HELP = `
|
|
105
|
+
${chalk_1.default.bold('Comandos disponibles:')}
|
|
106
|
+
${chalk_1.default.hex('#4CAF50')('/filter <tipo>')} Toggle filtro por tipo (ej: msg_in, error, tool_call)
|
|
107
|
+
${chalk_1.default.hex('#4CAF50')('/filters')} Mostrar filtros activos
|
|
108
|
+
${chalk_1.default.hex('#4CAF50')('/clear')} Limpiar pantalla
|
|
109
|
+
${chalk_1.default.hex('#4CAF50')('/json')} Toggle modo JSON expandido
|
|
110
|
+
${chalk_1.default.hex('#4CAF50')('/help')} Mostrar estos comandos
|
|
111
|
+
|
|
112
|
+
${chalk_1.default.bold('Tipos de evento:')}
|
|
113
|
+
${Object.entries(EVENT_COLORS).map(([key, val]) => ` ${chalk_1.default.hex(val.color)('●')} ${key}`).join('\n')}
|
|
114
|
+
`;
|
|
115
|
+
exports.monitorCommand = new commander_1.Command('monitor')
|
|
116
|
+
.description('Monitor en tiempo real de un agente (logs via SignalR)')
|
|
117
|
+
.requiredOption('-a, --agent-id <id>', 'ID del agente')
|
|
118
|
+
.option('-f, --filter <types>', 'Filtrar por tipos separados por coma (ej: msg_in,msg_out)')
|
|
119
|
+
.option('--no-session', 'Ocultar session ID')
|
|
120
|
+
.option('--json', 'Modo JSON crudo (para piping)', false)
|
|
121
|
+
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
122
|
+
.action(async (options) => {
|
|
123
|
+
try {
|
|
124
|
+
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
125
|
+
const baseUrl = getBaseUrl(credentials.zone, options.dev);
|
|
126
|
+
// Filtros iniciales
|
|
127
|
+
const activeFilters = new Set(options.filter ? options.filter.split(',').map(f => f.trim()) : []);
|
|
128
|
+
let jsonMode = options.json;
|
|
129
|
+
let lastSessionId = '';
|
|
130
|
+
// Cargar info del agente
|
|
131
|
+
let agentName = 'Agente';
|
|
132
|
+
try {
|
|
133
|
+
process.stdout.write(chalk_1.default.gray(' Conectando con agente...'));
|
|
134
|
+
const agent = new plazbot_1.Agent({
|
|
135
|
+
workspaceId: credentials.workspace,
|
|
136
|
+
apiKey: credentials.apiKey,
|
|
137
|
+
zone: credentials.zone,
|
|
138
|
+
...(options.dev && { customUrl: 'http://localhost:5090' }),
|
|
139
|
+
});
|
|
140
|
+
const info = await agent.getAgentById({ id: options.agentId });
|
|
141
|
+
if (info?.name)
|
|
142
|
+
agentName = info.name;
|
|
143
|
+
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
147
|
+
}
|
|
148
|
+
// Dibujar header
|
|
149
|
+
if (!jsonMode) {
|
|
150
|
+
console.clear();
|
|
151
|
+
printHeader(agentName);
|
|
152
|
+
}
|
|
153
|
+
// Conectar a SignalR
|
|
154
|
+
const hubUrl = `${baseUrl}/agentMonitorHub`;
|
|
155
|
+
const connection = new signalr_1.HubConnectionBuilder()
|
|
156
|
+
.withUrl(hubUrl, {
|
|
157
|
+
skipNegotiation: true,
|
|
158
|
+
transport: signalr_1.HttpTransportType.WebSockets,
|
|
159
|
+
})
|
|
160
|
+
.withAutomaticReconnect([0, 2000, 5000, 10000, 30000])
|
|
161
|
+
.build();
|
|
162
|
+
// Evento de log
|
|
163
|
+
connection.on('agent_log', (log) => {
|
|
164
|
+
// Aplicar filtros
|
|
165
|
+
if (activeFilters.size > 0 && !activeFilters.has(log.event_type))
|
|
166
|
+
return;
|
|
167
|
+
const line = renderLogLine(log, {
|
|
168
|
+
showSession: options.session,
|
|
169
|
+
jsonMode,
|
|
170
|
+
}, lastSessionId);
|
|
171
|
+
console.log(line);
|
|
172
|
+
lastSessionId = log.session_id || lastSessionId;
|
|
173
|
+
});
|
|
174
|
+
// Eventos de conexion
|
|
175
|
+
connection.onreconnecting(() => {
|
|
176
|
+
if (!jsonMode) {
|
|
177
|
+
console.log(chalk_1.default.hex('#FFA726')(' ⟳ Reconectando...'));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
connection.onreconnected(() => {
|
|
181
|
+
if (!jsonMode) {
|
|
182
|
+
console.log(chalk_1.default.hex('#4ade80')(' ● Reconectado'));
|
|
183
|
+
}
|
|
184
|
+
connection.invoke('JoinAgentMonitor', options.agentId).catch(() => { });
|
|
185
|
+
});
|
|
186
|
+
connection.onclose(() => {
|
|
187
|
+
if (!jsonMode) {
|
|
188
|
+
console.log(chalk_1.default.hex('#ef4444')(' ● Desconectado'));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
// Iniciar conexion
|
|
192
|
+
try {
|
|
193
|
+
await connection.start();
|
|
194
|
+
await connection.invoke('JoinAgentMonitor', options.agentId);
|
|
195
|
+
if (!jsonMode) {
|
|
196
|
+
console.log(chalk_1.default.hex('#4ade80')(' ● Conectado al monitor en tiempo real'));
|
|
197
|
+
console.log();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
logger_1.logger.error(`No se pudo conectar al monitor: ${err instanceof Error ? err.message : err}`);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
// readline para comandos interactivos
|
|
205
|
+
const rl = readline_1.default.createInterface({
|
|
206
|
+
input: process.stdin,
|
|
207
|
+
output: process.stdout,
|
|
208
|
+
prompt: '',
|
|
209
|
+
});
|
|
210
|
+
// No mostrar prompt para no interferir con el stream
|
|
211
|
+
rl.on('line', (input) => {
|
|
212
|
+
const cmd = input.trim().toLowerCase();
|
|
213
|
+
if (cmd === '/help') {
|
|
214
|
+
console.log(COMMANDS_HELP);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (cmd === '/clear') {
|
|
218
|
+
console.clear();
|
|
219
|
+
printHeader(agentName);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (cmd === '/json') {
|
|
223
|
+
jsonMode = !jsonMode;
|
|
224
|
+
console.log(chalk_1.default.gray(` Modo JSON: ${jsonMode ? 'activado' : 'desactivado'}`));
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (cmd === '/filters') {
|
|
228
|
+
if (activeFilters.size === 0) {
|
|
229
|
+
console.log(chalk_1.default.gray(' Sin filtros activos (mostrando todos)'));
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
console.log(chalk_1.default.gray(' Filtros activos: ') + chalk_1.default.white([...activeFilters].join(', ')));
|
|
233
|
+
}
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (cmd.startsWith('/filter ')) {
|
|
237
|
+
const filterType = cmd.substring(8).trim();
|
|
238
|
+
if (!filterType) {
|
|
239
|
+
console.log(chalk_1.default.gray(' Uso: /filter <tipo>'));
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (activeFilters.has(filterType)) {
|
|
243
|
+
activeFilters.delete(filterType);
|
|
244
|
+
console.log(chalk_1.default.gray(` Filtro removido: ${filterType}`));
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
activeFilters.add(filterType);
|
|
248
|
+
const config = EVENT_COLORS[filterType];
|
|
249
|
+
if (config) {
|
|
250
|
+
console.log(chalk_1.default.hex(config.color)(` ● Filtro agregado: ${filterType}`));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
console.log(chalk_1.default.gray(` Filtro agregado: ${filterType} (tipo desconocido)`));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (activeFilters.size > 0) {
|
|
257
|
+
console.log(chalk_1.default.gray(' Activos: ') + chalk_1.default.white([...activeFilters].join(', ')));
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
console.log(chalk_1.default.gray(' Sin filtros (mostrando todos)'));
|
|
261
|
+
}
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
// Cierre limpio
|
|
266
|
+
const cleanup = async () => {
|
|
267
|
+
if (!jsonMode) {
|
|
268
|
+
console.log(chalk_1.default.gray('\n Cerrando monitor...'));
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
if (connection.state === signalr_1.HubConnectionState.Connected) {
|
|
272
|
+
await connection.invoke('LeaveAgentMonitor', options.agentId);
|
|
273
|
+
}
|
|
274
|
+
await connection.stop();
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
// Ignorar errores al cerrar
|
|
278
|
+
}
|
|
279
|
+
rl.close();
|
|
280
|
+
if (!jsonMode) {
|
|
281
|
+
console.log(chalk_1.default.gray(' Monitor cerrado.\n'));
|
|
282
|
+
}
|
|
283
|
+
process.exit(0);
|
|
284
|
+
};
|
|
285
|
+
process.on('SIGINT', cleanup);
|
|
286
|
+
process.on('SIGTERM', cleanup);
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
const message = error instanceof Error ? error.message : 'Error desconocido';
|
|
290
|
+
logger_1.logger.error(message);
|
|
291
|
+
process.exit(1);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
@@ -28,10 +28,10 @@ exports.messageCommand = new commander_1.Command('message')
|
|
|
28
28
|
});
|
|
29
29
|
// Generar un sessionId si no se proporcionó uno
|
|
30
30
|
const sessionId = options.sessionId || crypto_1.default.randomUUID();
|
|
31
|
-
logger_1.logger.
|
|
32
|
-
logger_1.logger.
|
|
33
|
-
logger_1.logger.
|
|
34
|
-
logger_1.logger.
|
|
31
|
+
logger_1.logger.title('Enviando mensaje al agente');
|
|
32
|
+
logger_1.logger.label('ID del agente', options.agentId);
|
|
33
|
+
logger_1.logger.label('Pregunta', options.question);
|
|
34
|
+
logger_1.logger.label('ID de sesion', sessionId);
|
|
35
35
|
if (options.multipleAnswers) {
|
|
36
36
|
logger_1.logger.info('Modo: Múltiples respuestas');
|
|
37
37
|
}
|
|
@@ -41,20 +41,18 @@ exports.messageCommand = new commander_1.Command('message')
|
|
|
41
41
|
sessionId,
|
|
42
42
|
multipleAnswers: options.multipleAnswers
|
|
43
43
|
});
|
|
44
|
-
logger_1.logger.
|
|
45
|
-
logger_1.logger.divider();
|
|
44
|
+
logger_1.logger.title('Respuesta del Agente');
|
|
46
45
|
console.log(response.answer);
|
|
47
46
|
if (response.sources && response.sources.length > 0) {
|
|
48
|
-
logger_1.logger.
|
|
49
|
-
logger_1.logger.divider();
|
|
47
|
+
logger_1.logger.title('Fuentes');
|
|
50
48
|
response.sources.forEach((source) => {
|
|
51
|
-
logger_1.logger.
|
|
49
|
+
logger_1.logger.label('Titulo', source.title || 'Sin titulo');
|
|
52
50
|
if (source.url)
|
|
53
|
-
logger_1.logger.
|
|
51
|
+
logger_1.logger.label('URL', source.url);
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
|
-
logger_1.logger.
|
|
57
|
-
logger_1.logger.
|
|
54
|
+
logger_1.logger.title('Sesion');
|
|
55
|
+
logger_1.logger.label('ID', sessionId);
|
|
58
56
|
if (options.dev) {
|
|
59
57
|
logger_1.logger.warning('\nAmbiente: desarrollo');
|
|
60
58
|
}
|
|
@@ -35,7 +35,7 @@ exports.updateCommand = new commander_1.Command('update')
|
|
|
35
35
|
zone: credentials.zone,
|
|
36
36
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
37
37
|
});
|
|
38
|
-
logger_1.logger.
|
|
38
|
+
logger_1.logger.dim('Actualizando agente...');
|
|
39
39
|
// Actualizar el agente
|
|
40
40
|
const result = await agent.updateAgent(agentId, agentConfig);
|
|
41
41
|
logger_1.logger.success('Agente actualizado exitosamente');
|
|
@@ -20,10 +20,10 @@ exports.loginCommand = new commander_1.Command('init')
|
|
|
20
20
|
logger_1.logger.info('│' + ' Bienvenido a Plazbot CLI'.padEnd(69) + '│');
|
|
21
21
|
logger_1.logger.info('│' + ''.padEnd(69) + '│');
|
|
22
22
|
logger_1.logger.info('│' + ' Con esta herramienta podrás:'.padEnd(69) + '│');
|
|
23
|
-
logger_1.logger.info('│' + '
|
|
24
|
-
logger_1.logger.info('│' + '
|
|
25
|
-
logger_1.logger.info('│' + '
|
|
26
|
-
logger_1.logger.info('│' + '
|
|
23
|
+
logger_1.logger.info('│' + ' Crear y actualizar agentes'.padEnd(69) + '│');
|
|
24
|
+
logger_1.logger.info('│' + ' Gestionar configuraciones'.padEnd(69) + '│');
|
|
25
|
+
logger_1.logger.info('│' + ' Interactuar con tus agentes'.padEnd(69) + '│');
|
|
26
|
+
logger_1.logger.info('│' + ' Activar todas sus capacidades'.padEnd(69) + '│');
|
|
27
27
|
logger_1.logger.info('└' + '─'.repeat(70) + '┘\n');
|
|
28
28
|
await (0, credentials_1.saveCredentials)({
|
|
29
29
|
email: options.email,
|
|
@@ -32,14 +32,15 @@ exports.loginCommand = new commander_1.Command('init')
|
|
|
32
32
|
zone: options.zone
|
|
33
33
|
});
|
|
34
34
|
logger_1.logger.success('Configuración guardada exitosamente:');
|
|
35
|
-
logger_1.logger.
|
|
36
|
-
logger_1.logger.
|
|
37
|
-
logger_1.logger.
|
|
38
|
-
logger_1.logger.
|
|
39
|
-
logger_1.logger.
|
|
40
|
-
logger_1.logger.
|
|
41
|
-
logger_1.logger.
|
|
42
|
-
logger_1.logger.
|
|
35
|
+
logger_1.logger.label('Email', options.email);
|
|
36
|
+
logger_1.logger.label('Workspace', options.workspace);
|
|
37
|
+
logger_1.logger.label('Zona', options.zone);
|
|
38
|
+
logger_1.logger.title('Puedes comenzar usando los siguientes comandos');
|
|
39
|
+
logger_1.logger.dim('plazbot agent list - Ver tus agentes');
|
|
40
|
+
logger_1.logger.dim('plazbot agent templates - Crear agente desde plantilla');
|
|
41
|
+
logger_1.logger.dim('plazbot agent chat - Chatear con un agente');
|
|
42
|
+
logger_1.logger.dim('plazbot --help - Ver todos los comandos');
|
|
43
|
+
console.log();
|
|
43
44
|
if (options.dev) {
|
|
44
45
|
logger_1.logger.warning('Ambiente: desarrollo');
|
|
45
46
|
}
|
|
@@ -31,16 +31,11 @@ exports.addAgentCommand = new commander_1.Command('add-agent-portal')
|
|
|
31
31
|
});
|
|
32
32
|
// Obtener detalles del agente
|
|
33
33
|
const agentDetails = await agent.getAgentById({ id: options.agentId });
|
|
34
|
-
logger_1.logger.
|
|
35
|
-
logger_1.logger.
|
|
36
|
-
logger_1.logger.
|
|
37
|
-
logger_1.logger.
|
|
38
|
-
logger_1.logger.
|
|
39
|
-
logger_1.logger.info('\nAgente:');
|
|
40
|
-
logger_1.logger.info(` ID: ${agentDetails.id}`);
|
|
41
|
-
logger_1.logger.info(` Nombre: ${agentDetails.name}`);
|
|
42
|
-
logger_1.logger.divider();
|
|
43
|
-
logger_1.logger.info('\n🔄 Agregando agente al portal...');
|
|
34
|
+
logger_1.logger.title('Detalles de la operacion');
|
|
35
|
+
logger_1.logger.label('Portal ID', portalDetails.portal?.id || options.portalId);
|
|
36
|
+
logger_1.logger.label('Portal Nombre', portalDetails.portal?.name || 'N/A');
|
|
37
|
+
logger_1.logger.label('Agente ID', agentDetails.id);
|
|
38
|
+
logger_1.logger.label('Agente Nombre', agentDetails.name);
|
|
44
39
|
await portal.addAgentToPortal({
|
|
45
40
|
portalId: options.portalId,
|
|
46
41
|
id: options.agentId
|
|
@@ -4,6 +4,7 @@ exports.addLinkCommand = void 0;
|
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const plazbot_1 = require("plazbot");
|
|
6
6
|
const credentials_1 = require("../../utils/credentials");
|
|
7
|
+
const logger_1 = require("../../utils/logger");
|
|
7
8
|
exports.addLinkCommand = new commander_1.Command('add-link')
|
|
8
9
|
.description('Agregar un enlace al portal')
|
|
9
10
|
.argument('<portalId>', 'ID del portal')
|
|
@@ -24,10 +25,10 @@ exports.addLinkCommand = new commander_1.Command('add-link')
|
|
|
24
25
|
value: options.title,
|
|
25
26
|
url: options.url
|
|
26
27
|
});
|
|
27
|
-
|
|
28
|
+
logger_1.logger.success('Enlace agregado exitosamente');
|
|
28
29
|
}
|
|
29
30
|
catch (error) {
|
|
30
|
-
|
|
31
|
+
logger_1.logger.error(error.message);
|
|
31
32
|
process.exit(1);
|
|
32
33
|
}
|
|
33
34
|
});
|
|
@@ -4,6 +4,7 @@ exports.clearLinksCommand = void 0;
|
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const plazbot_1 = require("plazbot");
|
|
6
6
|
const credentials_1 = require("../../utils/credentials");
|
|
7
|
+
const logger_1 = require("../../utils/logger");
|
|
7
8
|
exports.clearLinksCommand = new commander_1.Command('clear-links')
|
|
8
9
|
.description('Eliminar todos los enlaces del portal')
|
|
9
10
|
.argument('<portalId>', 'ID del portal')
|
|
@@ -18,10 +19,10 @@ exports.clearLinksCommand = new commander_1.Command('clear-links')
|
|
|
18
19
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
19
20
|
});
|
|
20
21
|
await portal.clearLinks(portalId);
|
|
21
|
-
|
|
22
|
+
logger_1.logger.success('Enlaces eliminados exitosamente');
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
|
-
|
|
25
|
+
logger_1.logger.error(error.message);
|
|
25
26
|
process.exit(1);
|
|
26
27
|
}
|
|
27
28
|
});
|
|
@@ -20,12 +20,10 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
20
20
|
zone: credentials.zone,
|
|
21
21
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
22
22
|
});
|
|
23
|
-
logger_1.logger.info('\n🚀 Creando portal...');
|
|
24
23
|
const portalCreated = await portal.addPortal({
|
|
25
24
|
name: options.name,
|
|
26
25
|
title: options.title,
|
|
27
26
|
zone: credentials.zone,
|
|
28
|
-
// Valores por defecto
|
|
29
27
|
subtitle: "",
|
|
30
28
|
logo: "",
|
|
31
29
|
logodark: "",
|
|
@@ -34,11 +32,9 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
34
32
|
brandOff: false
|
|
35
33
|
});
|
|
36
34
|
logger_1.logger.success('Portal creado exitosamente');
|
|
37
|
-
logger_1.logger.
|
|
38
|
-
logger_1.logger.
|
|
39
|
-
logger_1.logger.
|
|
40
|
-
logger_1.logger.info(`URL: ${portalCreated.url}`);
|
|
41
|
-
logger_1.logger.divider();
|
|
35
|
+
logger_1.logger.title('Detalles del portal');
|
|
36
|
+
logger_1.logger.label('ID', portalCreated.id);
|
|
37
|
+
logger_1.logger.label('URL', portalCreated.url);
|
|
42
38
|
if (options.dev) {
|
|
43
39
|
logger_1.logger.warning('\nAmbiente: desarrollo');
|
|
44
40
|
}
|
|
@@ -26,11 +26,10 @@ exports.deleteCommand = new commander_1.Command('delete')
|
|
|
26
26
|
});
|
|
27
27
|
// Obtener detalles del portal para mostrar qué se va a eliminar
|
|
28
28
|
const portalDetails = await portal.getPortal(portalId);
|
|
29
|
-
logger_1.logger.
|
|
30
|
-
logger_1.logger.
|
|
31
|
-
logger_1.logger.
|
|
32
|
-
logger_1.logger.
|
|
33
|
-
logger_1.logger.info(`URL: ${portalDetails.portal.url}`);
|
|
29
|
+
logger_1.logger.title('Portal a eliminar');
|
|
30
|
+
logger_1.logger.label('ID', portalDetails.portal.id);
|
|
31
|
+
logger_1.logger.label('Nombre', portalDetails.portal.name);
|
|
32
|
+
logger_1.logger.label('URL', portalDetails.portal.url);
|
|
34
33
|
if (!options.force) {
|
|
35
34
|
const { confirm } = await inquirer_1.default.prompt([{
|
|
36
35
|
type: 'confirm',
|
|
@@ -43,7 +42,7 @@ exports.deleteCommand = new commander_1.Command('delete')
|
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
logger_1.logger.
|
|
45
|
+
logger_1.logger.dim('Eliminando portal...');
|
|
47
46
|
await portal.deletePortal(portalId);
|
|
48
47
|
logger_1.logger.success('Portal eliminado exitosamente');
|
|
49
48
|
if (options.dev) {
|