plazbot-cli 0.2.6 → 0.2.8

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.
@@ -84,22 +84,60 @@ async function connectChannelFlow(ctx) {
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
+ // La API retorna un array [{ integrations: [...] }]
88
+ const wsData = Array.isArray(wkRes.data) ? wkRes.data[0] : wkRes.data;
89
+ const integrations = wsData?.integrations || [];
88
90
  prevIntegrationIds = new Set(integrations.map((i) => i.id));
89
91
  }
90
92
  catch {
91
93
  // Si falla, se parte de vacio
92
94
  }
93
- // Polling para detectar nueva integracion
94
- const pollSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Esperando conexion... (Ctrl+C para cancelar)'), spinner: 'dots', color: 'cyan' }).start();
95
+ // Polling para detectar nueva integracion (Enter para saltar)
96
+ const pollSpinner = (0, ora_1.default)({ text: chalk_1.default.gray('Esperando conexion... (Enter para saltar)'), spinner: 'dots', color: 'cyan' }).start();
95
97
  const POLL_INTERVAL = 5000;
96
98
  const MAX_POLLS = 60; // 5 minutos
97
99
  let detected = null;
100
+ let skipped = false;
101
+ // Escuchar Enter para saltar el polling
102
+ const skipPromise = new Promise(resolve => {
103
+ const onData = (data) => {
104
+ if (data.toString().includes('\n') || data.toString().includes('\r')) {
105
+ skipped = true;
106
+ process.stdin.removeListener('data', onData);
107
+ if (wasRaw)
108
+ process.stdin.setRawMode(false);
109
+ resolve();
110
+ }
111
+ };
112
+ const wasRaw = process.stdin.isRaw;
113
+ if (process.stdin.isTTY)
114
+ process.stdin.setRawMode(true);
115
+ process.stdin.resume();
116
+ process.stdin.on('data', onData);
117
+ // Limpiar si termina el polling naturalmente
118
+ setTimeout(() => {
119
+ process.stdin.removeListener('data', onData);
120
+ if (process.stdin.isTTY && wasRaw !== undefined) {
121
+ try {
122
+ process.stdin.setRawMode(wasRaw);
123
+ }
124
+ catch { }
125
+ }
126
+ resolve();
127
+ }, POLL_INTERVAL * MAX_POLLS + 1000);
128
+ });
98
129
  for (let i = 0; i < MAX_POLLS; i++) {
99
- await new Promise(r => setTimeout(r, POLL_INTERVAL));
130
+ await Promise.race([
131
+ new Promise(r => setTimeout(r, POLL_INTERVAL)),
132
+ skipPromise,
133
+ ]);
134
+ if (skipped)
135
+ break;
100
136
  try {
101
137
  const wkRes = await axios_1.default.get(`${baseUrl}/api/workspace/${ctx.workspaceId}`, { headers });
102
- const integrations = wkRes.data?.integrations || [];
138
+ // La API retorna un array [{ integrations: [...] }]
139
+ const wsData = Array.isArray(wkRes.data) ? wkRes.data[0] : wkRes.data;
140
+ const integrations = wsData?.integrations || [];
103
141
  // Buscar integraciones nuevas (cualquier ID que no existia antes)
104
142
  const newOnes = integrations.filter((ig) => !prevIntegrationIds.has(ig.id));
105
143
  if (newOnes.length > 0) {
@@ -114,7 +152,7 @@ async function connectChannelFlow(ctx) {
114
152
  // Ignorar errores de poll individual
115
153
  }
116
154
  const elapsed = Math.floor(((i + 1) * POLL_INTERVAL) / 1000);
117
- pollSpinner.text = chalk_1.default.gray(`Esperando conexion... ${elapsed}s`);
155
+ pollSpinner.text = chalk_1.default.gray(`Esperando conexion... ${elapsed}s (Enter para saltar)`);
118
156
  }
119
157
  if (detected) {
120
158
  const detectedName = detected.aliasName || detected.cellphoneNumberFormat || detected.cellphoneNumber || detected.srcName || detected.id;
@@ -133,7 +171,7 @@ async function connectChannelFlow(ctx) {
133
171
  }
134
172
  }
135
173
  else {
136
- pollSpinner.warn(chalk_1.default.hex('#FFA726')('Timeout: no se detecto una conexion.'));
174
+ pollSpinner.warn(chalk_1.default.hex('#FFA726')(skipped ? 'Polling omitido.' : 'Timeout: no se detecto una conexion.'));
137
175
  const { action } = await inquirer_1.default.prompt([{
138
176
  type: 'list', name: 'action',
139
177
  message: 'Que deseas hacer?',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plazbot-cli",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "CLI para Plazbot SDK",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {
@@ -186,23 +186,56 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
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
+ // La API retorna un array [{ integrations: [...] }]
190
+ const wsData = Array.isArray(wkRes.data) ? wkRes.data[0] : wkRes.data;
191
+ const integrations = wsData?.integrations || [];
190
192
  prevIntegrationIds = new Set(integrations.map((i: any) => i.id));
191
193
  } catch {
192
194
  // Si falla, se parte de vacio
193
195
  }
194
196
 
195
- // Polling para detectar nueva integracion
196
- const pollSpinner = ora({ text: chalk.gray('Esperando conexion... (Ctrl+C para cancelar)'), spinner: 'dots', color: 'cyan' }).start();
197
+ // Polling para detectar nueva integracion (Enter para saltar)
198
+ const pollSpinner = ora({ text: chalk.gray('Esperando conexion... (Enter para saltar)'), spinner: 'dots', color: 'cyan' }).start();
197
199
  const POLL_INTERVAL = 5000;
198
200
  const MAX_POLLS = 60; // 5 minutos
199
201
  let detected: any = null;
202
+ let skipped = false;
203
+
204
+ // Escuchar Enter para saltar el polling
205
+ const skipPromise = new Promise<void>(resolve => {
206
+ const onData = (data: Buffer) => {
207
+ if (data.toString().includes('\n') || data.toString().includes('\r')) {
208
+ skipped = true;
209
+ process.stdin.removeListener('data', onData);
210
+ if (wasRaw) process.stdin.setRawMode(false);
211
+ resolve();
212
+ }
213
+ };
214
+ const wasRaw = process.stdin.isRaw;
215
+ if (process.stdin.isTTY) process.stdin.setRawMode(true);
216
+ process.stdin.resume();
217
+ process.stdin.on('data', onData);
218
+ // Limpiar si termina el polling naturalmente
219
+ setTimeout(() => {
220
+ process.stdin.removeListener('data', onData);
221
+ if (process.stdin.isTTY && wasRaw !== undefined) {
222
+ try { process.stdin.setRawMode(wasRaw); } catch {}
223
+ }
224
+ resolve();
225
+ }, POLL_INTERVAL * MAX_POLLS + 1000);
226
+ });
200
227
 
201
228
  for (let i = 0; i < MAX_POLLS; i++) {
202
- await new Promise(r => setTimeout(r, POLL_INTERVAL));
229
+ await Promise.race([
230
+ new Promise(r => setTimeout(r, POLL_INTERVAL)),
231
+ skipPromise,
232
+ ]);
233
+ if (skipped) break;
203
234
  try {
204
235
  const wkRes = await axios.get(`${baseUrl}/api/workspace/${ctx.workspaceId}`, { headers });
205
- const integrations = wkRes.data?.integrations || [];
236
+ // La API retorna un array [{ integrations: [...] }]
237
+ const wsData = Array.isArray(wkRes.data) ? wkRes.data[0] : wkRes.data;
238
+ const integrations = wsData?.integrations || [];
206
239
 
207
240
  // Buscar integraciones nuevas (cualquier ID que no existia antes)
208
241
  const newOnes = integrations.filter((ig: any) => !prevIntegrationIds.has(ig.id));
@@ -218,7 +251,7 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
218
251
  // Ignorar errores de poll individual
219
252
  }
220
253
  const elapsed = Math.floor(((i + 1) * POLL_INTERVAL) / 1000);
221
- pollSpinner.text = chalk.gray(`Esperando conexion... ${elapsed}s`);
254
+ pollSpinner.text = chalk.gray(`Esperando conexion... ${elapsed}s (Enter para saltar)`);
222
255
  }
223
256
 
224
257
  if (detected) {
@@ -239,7 +272,7 @@ async function connectChannelFlow(ctx: WizardContext): Promise<AgentChannel[]> {
239
272
  console.log(chalk.hex('#4ade80')(' Canal asociado correctamente.'));
240
273
  }
241
274
  } else {
242
- pollSpinner.warn(chalk.hex('#FFA726')('Timeout: no se detecto una conexion.'));
275
+ pollSpinner.warn(chalk.hex('#FFA726')(skipped ? 'Polling omitido.' : 'Timeout: no se detecto una conexion.'));
243
276
  const { action } = await (inquirer as any).prompt([{
244
277
  type: 'list', name: 'action',
245
278
  message: 'Que deseas hacer?',