plazbot-cli 0.2.5 → 0.2.6
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.
|
@@ -119,11 +119,18 @@ exports.monitorCommand = new commander_1.Command('monitor')
|
|
|
119
119
|
.option('-f, --filter <types>', 'Filtrar por tipos separados por coma (ej: msg_in,msg_out)')
|
|
120
120
|
.option('--no-session', 'Ocultar session ID')
|
|
121
121
|
.option('--json', 'Modo JSON crudo (para piping)', false)
|
|
122
|
+
.option('-w, --workspace <id>', 'Workspace ID (sobreescribe config local)')
|
|
123
|
+
.option('-z, --zone <zone>', 'Zona LA o EU (sobreescribe config local)')
|
|
122
124
|
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
123
125
|
.action(async (options) => {
|
|
124
126
|
try {
|
|
125
127
|
const credentials = await (0, credentials_1.getStoredCredentials)();
|
|
126
|
-
const
|
|
128
|
+
const effectiveWorkspace = options.workspace || credentials.workspace;
|
|
129
|
+
const effectiveZone = (options.zone?.toUpperCase() === 'EU' ? 'EU' : options.zone?.toUpperCase() === 'LA' ? 'LA' : credentials.zone);
|
|
130
|
+
const baseUrl = getBaseUrl(effectiveZone, options.dev);
|
|
131
|
+
if (options.workspace || options.zone) {
|
|
132
|
+
console.log(chalk_1.default.hex('#FFA726')(`\n Modo soporte: workspace=${effectiveWorkspace} zona=${effectiveZone}`));
|
|
133
|
+
}
|
|
127
134
|
// Filtros iniciales
|
|
128
135
|
const activeFilters = new Set(options.filter ? options.filter.split(',').map(f => f.trim()) : []);
|
|
129
136
|
let jsonMode = options.json;
|
|
@@ -133,9 +140,9 @@ exports.monitorCommand = new commander_1.Command('monitor')
|
|
|
133
140
|
try {
|
|
134
141
|
process.stdout.write(chalk_1.default.gray(' Conectando con agente...'));
|
|
135
142
|
const agent = new plazbot_1.Agent({
|
|
136
|
-
workspaceId:
|
|
143
|
+
workspaceId: effectiveWorkspace,
|
|
137
144
|
apiKey: credentials.apiKey,
|
|
138
|
-
zone:
|
|
145
|
+
zone: effectiveZone,
|
|
139
146
|
...(options.dev && { customUrl: 'http://localhost:5090' }),
|
|
140
147
|
});
|
|
141
148
|
const info = await agent.getAgentById({ id: options.agentId });
|
|
@@ -10,7 +10,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
10
10
|
const ora_1 = __importDefault(require("ora"));
|
|
11
11
|
const ui_1 = require("../../utils/ui");
|
|
12
12
|
const MODELS = {
|
|
13
|
-
openai: ['gpt-4o', 'gpt-4', 'gpt-3.5-turbo', 'o1-preview', 'o1-mini'],
|
|
13
|
+
openai: ['gpt-4o', 'gpt-4o-mini', 'gpt-4', 'gpt-3.5-turbo', 'o1-preview', 'o1-mini'],
|
|
14
14
|
claude: ['claude-3-5-sonnet-20241022', 'claude-3-opus-20240229', 'claude-3-haiku-20240307'],
|
|
15
15
|
gemini: ['gemini-2.0-flash', 'gemini-1.5-pro', 'gemini-1.5-flash'],
|
|
16
16
|
};
|
|
@@ -71,20 +71,20 @@ async function connectChannelFlow(ctx) {
|
|
|
71
71
|
}
|
|
72
72
|
const shortUrl = linkRes.data.data?.shortUrl || '';
|
|
73
73
|
spinner.stop();
|
|
74
|
-
// Mostrar link
|
|
74
|
+
// Mostrar link
|
|
75
75
|
console.log();
|
|
76
|
-
console.log(chalk_1.default.hex('#4CAF50')('
|
|
77
|
-
console.log(chalk_1.default.
|
|
78
|
-
console.log(
|
|
79
|
-
console.log(
|
|
80
|
-
console.log(
|
|
81
|
-
console.log(chalk_1.default.hex('#4CAF50')('
|
|
76
|
+
console.log(chalk_1.default.hex('#4CAF50')(' ─'.repeat(32)));
|
|
77
|
+
console.log(chalk_1.default.bold(` Envia este link para conectar ${channelLabel}:`));
|
|
78
|
+
console.log();
|
|
79
|
+
console.log(' ' + chalk_1.default.hex('#22d3ee')(shortUrl));
|
|
80
|
+
console.log();
|
|
81
|
+
console.log(chalk_1.default.hex('#4CAF50')(' ─'.repeat(32)));
|
|
82
82
|
console.log();
|
|
83
83
|
// Snapshot de integraciones actuales
|
|
84
84
|
let prevIntegrationIds = new Set();
|
|
85
85
|
try {
|
|
86
86
|
const wkRes = await axios_1.default.get(`${baseUrl}/api/workspace/${ctx.workspaceId}`, { headers });
|
|
87
|
-
const integrations = wkRes.data?.integrations ||
|
|
87
|
+
const integrations = wkRes.data?.integrations || [];
|
|
88
88
|
prevIntegrationIds = new Set(integrations.map((i) => i.id));
|
|
89
89
|
}
|
|
90
90
|
catch {
|
|
@@ -99,12 +99,14 @@ async function connectChannelFlow(ctx) {
|
|
|
99
99
|
await new Promise(r => setTimeout(r, POLL_INTERVAL));
|
|
100
100
|
try {
|
|
101
101
|
const wkRes = await axios_1.default.get(`${baseUrl}/api/workspace/${ctx.workspaceId}`, { headers });
|
|
102
|
-
const integrations = wkRes.data?.integrations ||
|
|
103
|
-
// Buscar integraciones nuevas
|
|
104
|
-
const
|
|
105
|
-
const newOnes = integrations.filter((ig) => !prevIntegrationIds.has(ig.id) && ig.type === targetType);
|
|
102
|
+
const integrations = wkRes.data?.integrations || [];
|
|
103
|
+
// Buscar integraciones nuevas (cualquier ID que no existia antes)
|
|
104
|
+
const newOnes = integrations.filter((ig) => !prevIntegrationIds.has(ig.id));
|
|
106
105
|
if (newOnes.length > 0) {
|
|
107
|
-
|
|
106
|
+
// Preferir la que coincida con el tipo solicitado
|
|
107
|
+
const targetType = channelType === 'whatsapp_business' ? 'whatsapp' : channelType;
|
|
108
|
+
const matchingNew = newOnes.find((ig) => ig.type === targetType);
|
|
109
|
+
detected = matchingNew || newOnes[0];
|
|
108
110
|
break;
|
|
109
111
|
}
|
|
110
112
|
}
|
|
@@ -115,7 +117,8 @@ async function connectChannelFlow(ctx) {
|
|
|
115
117
|
pollSpinner.text = chalk_1.default.gray(`Esperando conexion... ${elapsed}s`);
|
|
116
118
|
}
|
|
117
119
|
if (detected) {
|
|
118
|
-
|
|
120
|
+
const detectedName = detected.aliasName || detected.cellphoneNumberFormat || detected.cellphoneNumber || detected.srcName || detected.id;
|
|
121
|
+
pollSpinner.succeed(chalk_1.default.hex('#4ade80')(`Conexion detectada: ${detectedName} (${channelLabel})`));
|
|
119
122
|
const { associate } = await inquirer_1.default.prompt([{
|
|
120
123
|
type: 'confirm', name: 'associate',
|
|
121
124
|
message: 'Deseas asociar este canal al agente?', default: true,
|
|
@@ -424,15 +427,13 @@ async function runAgentWizard(zone, workspaceId, apiKey, dev) {
|
|
|
424
427
|
const aiConfig = await inquirer_1.default.prompt([
|
|
425
428
|
{ type: 'list', name: 'model', message: 'Modelo:', choices: models },
|
|
426
429
|
{ type: 'password', name: 'apiToken', message: 'API Token:', mask: '*', validate: (v) => v.length > 0 || 'Requerido' },
|
|
427
|
-
{ type: 'number', name: 'temperature', message: 'Temperatura (0-2):', default: 0.7 },
|
|
428
|
-
{ type: 'number', name: 'maxTokens', message: 'Max tokens (1024-16384):', default: 4096 },
|
|
429
430
|
]);
|
|
430
431
|
aiProviders.push({
|
|
431
432
|
provider: ai.provider,
|
|
432
433
|
model: aiConfig.model,
|
|
433
434
|
apiToken: aiConfig.apiToken,
|
|
434
|
-
temperature:
|
|
435
|
-
maxTokens:
|
|
435
|
+
temperature: 0.7,
|
|
436
|
+
maxTokens: 4096,
|
|
436
437
|
isDefault: true,
|
|
437
438
|
});
|
|
438
439
|
}
|
package/package.json
CHANGED
|
@@ -153,17 +153,28 @@ export const monitorCommand = new Command('monitor')
|
|
|
153
153
|
.option('-f, --filter <types>', 'Filtrar por tipos separados por coma (ej: msg_in,msg_out)')
|
|
154
154
|
.option('--no-session', 'Ocultar session ID')
|
|
155
155
|
.option('--json', 'Modo JSON crudo (para piping)', false)
|
|
156
|
+
.option('-w, --workspace <id>', 'Workspace ID (sobreescribe config local)')
|
|
157
|
+
.option('-z, --zone <zone>', 'Zona LA o EU (sobreescribe config local)')
|
|
156
158
|
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
157
159
|
.action(async (options: {
|
|
158
160
|
agentId: string;
|
|
159
161
|
filter?: string;
|
|
160
162
|
session: boolean;
|
|
161
163
|
json: boolean;
|
|
164
|
+
workspace?: string;
|
|
165
|
+
zone?: string;
|
|
162
166
|
dev: boolean;
|
|
163
167
|
}) => {
|
|
164
168
|
try {
|
|
165
169
|
const credentials = await getStoredCredentials();
|
|
166
|
-
|
|
170
|
+
|
|
171
|
+
const effectiveWorkspace = options.workspace || credentials.workspace;
|
|
172
|
+
const effectiveZone = (options.zone?.toUpperCase() === 'EU' ? 'EU' : options.zone?.toUpperCase() === 'LA' ? 'LA' : credentials.zone) as 'LA' | 'EU';
|
|
173
|
+
const baseUrl = getBaseUrl(effectiveZone, options.dev);
|
|
174
|
+
|
|
175
|
+
if (options.workspace || options.zone) {
|
|
176
|
+
console.log(chalk.hex('#FFA726')(`\n Modo soporte: workspace=${effectiveWorkspace} zona=${effectiveZone}`));
|
|
177
|
+
}
|
|
167
178
|
|
|
168
179
|
// Filtros iniciales
|
|
169
180
|
const activeFilters: Set<string> = new Set(
|
|
@@ -177,9 +188,9 @@ export const monitorCommand = new Command('monitor')
|
|
|
177
188
|
try {
|
|
178
189
|
process.stdout.write(chalk.gray(' Conectando con agente...'));
|
|
179
190
|
const agent = new Agent({
|
|
180
|
-
workspaceId:
|
|
191
|
+
workspaceId: effectiveWorkspace,
|
|
181
192
|
apiKey: credentials.apiKey,
|
|
182
|
-
zone:
|
|
193
|
+
zone: effectiveZone,
|
|
183
194
|
...(options.dev && { customUrl: 'http://localhost:5090' }),
|
|
184
195
|
});
|
|
185
196
|
const info: any = await agent.getAgentById({ id: options.agentId });
|
|
@@ -89,7 +89,7 @@ interface AgentExample {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const MODELS: Record<string, string[]> = {
|
|
92
|
-
openai: ['gpt-4o', 'gpt-4', 'gpt-3.5-turbo', 'o1-preview', 'o1-mini'],
|
|
92
|
+
openai: ['gpt-4o', 'gpt-4o-mini', 'gpt-4', 'gpt-3.5-turbo', 'o1-preview', 'o1-mini'],
|
|
93
93
|
claude: ['claude-3-5-sonnet-20241022', 'claude-3-opus-20240229', 'claude-3-haiku-20240307'],
|
|
94
94
|
gemini: ['gemini-2.0-flash', 'gemini-1.5-pro', 'gemini-1.5-flash'],
|
|
95
95
|
};
|
|
@@ -172,21 +172,21 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
|
172
172
|
const shortUrl = linkRes.data.data?.shortUrl || '';
|
|
173
173
|
spinner.stop();
|
|
174
174
|
|
|
175
|
-
// Mostrar link
|
|
175
|
+
// Mostrar link
|
|
176
176
|
console.log();
|
|
177
|
-
console.log(chalk.hex('#4CAF50')('
|
|
178
|
-
console.log(chalk.
|
|
179
|
-
console.log(
|
|
180
|
-
console.log(
|
|
181
|
-
console.log(
|
|
182
|
-
console.log(chalk.hex('#4CAF50')('
|
|
177
|
+
console.log(chalk.hex('#4CAF50')(' ─'.repeat(32)));
|
|
178
|
+
console.log(chalk.bold(` Envia este link para conectar ${channelLabel}:`));
|
|
179
|
+
console.log();
|
|
180
|
+
console.log(' ' + chalk.hex('#22d3ee')(shortUrl));
|
|
181
|
+
console.log();
|
|
182
|
+
console.log(chalk.hex('#4CAF50')(' ─'.repeat(32)));
|
|
183
183
|
console.log();
|
|
184
184
|
|
|
185
185
|
// Snapshot de integraciones actuales
|
|
186
186
|
let prevIntegrationIds: Set<string> = new Set();
|
|
187
187
|
try {
|
|
188
188
|
const wkRes = await axios.get(`${baseUrl}/api/workspace/${ctx.workspaceId}`, { headers });
|
|
189
|
-
const integrations = wkRes.data?.integrations ||
|
|
189
|
+
const integrations = wkRes.data?.integrations || [];
|
|
190
190
|
prevIntegrationIds = new Set(integrations.map((i: any) => i.id));
|
|
191
191
|
} catch {
|
|
192
192
|
// Si falla, se parte de vacio
|
|
@@ -202,16 +202,16 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
|
202
202
|
await new Promise(r => setTimeout(r, POLL_INTERVAL));
|
|
203
203
|
try {
|
|
204
204
|
const wkRes = await axios.get(`${baseUrl}/api/workspace/${ctx.workspaceId}`, { headers });
|
|
205
|
-
const integrations = wkRes.data?.integrations ||
|
|
205
|
+
const integrations = wkRes.data?.integrations || [];
|
|
206
206
|
|
|
207
|
-
// Buscar integraciones nuevas
|
|
208
|
-
const
|
|
209
|
-
const newOnes = integrations.filter((ig: any) =>
|
|
210
|
-
!prevIntegrationIds.has(ig.id) && ig.type === targetType
|
|
211
|
-
);
|
|
207
|
+
// Buscar integraciones nuevas (cualquier ID que no existia antes)
|
|
208
|
+
const newOnes = integrations.filter((ig: any) => !prevIntegrationIds.has(ig.id));
|
|
212
209
|
|
|
213
210
|
if (newOnes.length > 0) {
|
|
214
|
-
|
|
211
|
+
// Preferir la que coincida con el tipo solicitado
|
|
212
|
+
const targetType = channelType === 'whatsapp_business' ? 'whatsapp' : channelType;
|
|
213
|
+
const matchingNew = newOnes.find((ig: any) => ig.type === targetType);
|
|
214
|
+
detected = matchingNew || newOnes[0];
|
|
215
215
|
break;
|
|
216
216
|
}
|
|
217
217
|
} catch {
|
|
@@ -222,7 +222,8 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
if (detected) {
|
|
225
|
-
|
|
225
|
+
const detectedName = detected.aliasName || detected.cellphoneNumberFormat || detected.cellphoneNumber || detected.srcName || detected.id;
|
|
226
|
+
pollSpinner.succeed(chalk.hex('#4ade80')(`Conexion detectada: ${detectedName} (${channelLabel})`));
|
|
226
227
|
|
|
227
228
|
const { associate } = await (inquirer as any).prompt([{
|
|
228
229
|
type: 'confirm', name: 'associate',
|
|
@@ -551,16 +552,14 @@ export async function runAgentWizard(zone: string, workspaceId?: string, apiKey?
|
|
|
551
552
|
const aiConfig = await (inquirer as any).prompt([
|
|
552
553
|
{ type: 'list', name: 'model', message: 'Modelo:', choices: models },
|
|
553
554
|
{ type: 'password', name: 'apiToken', message: 'API Token:', mask: '*', validate: (v: string) => v.length > 0 || 'Requerido' },
|
|
554
|
-
{ type: 'number', name: 'temperature', message: 'Temperatura (0-2):', default: 0.7 },
|
|
555
|
-
{ type: 'number', name: 'maxTokens', message: 'Max tokens (1024-16384):', default: 4096 },
|
|
556
555
|
]);
|
|
557
556
|
|
|
558
557
|
aiProviders.push({
|
|
559
558
|
provider: ai.provider,
|
|
560
559
|
model: aiConfig.model,
|
|
561
560
|
apiToken: aiConfig.apiToken,
|
|
562
|
-
temperature:
|
|
563
|
-
maxTokens:
|
|
561
|
+
temperature: 0.7,
|
|
562
|
+
maxTokens: 4096,
|
|
564
563
|
isDefault: true,
|
|
565
564
|
});
|
|
566
565
|
}
|