plazbot-cli 0.2.26 → 0.3.1

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 (178) hide show
  1. package/CLAUDE.md +34 -5
  2. package/README.md +21 -0
  3. package/dist/cli.js +32 -20
  4. package/dist/commands/agent/ai-config.js +98 -50
  5. package/dist/commands/agent/chat.js +80 -74
  6. package/dist/commands/agent/copy.js +23 -21
  7. package/dist/commands/agent/create.js +42 -72
  8. package/dist/commands/agent/delete.js +29 -30
  9. package/dist/commands/agent/enable-widget.js +30 -26
  10. package/dist/commands/agent/export.js +90 -77
  11. package/dist/commands/agent/files.js +68 -60
  12. package/dist/commands/agent/get.js +101 -87
  13. package/dist/commands/agent/index.js +53 -39
  14. package/dist/commands/agent/list.js +26 -24
  15. package/dist/commands/agent/monitor.js +91 -86
  16. package/dist/commands/agent/on-message.js +40 -37
  17. package/dist/commands/agent/set.js +62 -59
  18. package/dist/commands/agent/templates.js +109 -108
  19. package/dist/commands/agent/tools.js +64 -65
  20. package/dist/commands/agent/update.js +28 -27
  21. package/dist/commands/agent/validate.js +127 -0
  22. package/dist/commands/agent/wizard.js +152 -159
  23. package/dist/commands/auth/index.js +7 -10
  24. package/dist/commands/auth/login.js +50 -37
  25. package/dist/commands/auth/logout.js +16 -14
  26. package/dist/commands/auth/status.js +19 -16
  27. package/dist/commands/portal/add-agent.js +26 -24
  28. package/dist/commands/portal/add-link.js +21 -17
  29. package/dist/commands/portal/clear-links.js +17 -15
  30. package/dist/commands/portal/create.js +25 -21
  31. package/dist/commands/portal/delete.js +31 -30
  32. package/dist/commands/portal/get.js +33 -31
  33. package/dist/commands/portal/index.js +30 -22
  34. package/dist/commands/portal/list.js +34 -30
  35. package/dist/commands/portal/update.js +41 -33
  36. package/dist/commands/whatsapp/broadcast.js +40 -37
  37. package/dist/commands/whatsapp/channels.js +40 -34
  38. package/dist/commands/whatsapp/chat.js +33 -32
  39. package/dist/commands/whatsapp/connect.js +53 -52
  40. package/dist/commands/whatsapp/delete-webhook.js +19 -17
  41. package/dist/commands/whatsapp/index.js +35 -25
  42. package/dist/commands/whatsapp/register-webhook.js +21 -19
  43. package/dist/commands/whatsapp/send-template.js +39 -31
  44. package/dist/commands/whatsapp/send.js +27 -23
  45. package/dist/commands/whatsapp/widget.js +35 -31
  46. package/dist/commands/workers/deploy.js +49 -44
  47. package/dist/commands/workers/index.js +28 -18
  48. package/dist/commands/workers/list.js +43 -35
  49. package/dist/commands/workers/logs.js +38 -32
  50. package/dist/commands/workers/remove.js +38 -37
  51. package/dist/commands/workers/secret.js +63 -58
  52. package/dist/commands/workers/test.js +44 -36
  53. package/dist/schemas/agent.config.schema.json +569 -0
  54. package/dist/studio/api/sseClient.js +97 -0
  55. package/dist/studio/api/studioApi.js +25 -0
  56. package/dist/studio/api/types.js +16 -0
  57. package/dist/studio/components/AgentPanel.js +35 -0
  58. package/dist/studio/components/App.js +214 -0
  59. package/dist/studio/components/ChatLog.js +59 -0
  60. package/dist/studio/components/Footer.js +11 -0
  61. package/dist/studio/components/Header.js +8 -0
  62. package/dist/studio/components/Input.js +15 -0
  63. package/dist/studio/components/Message.js +56 -0
  64. package/dist/studio/components/Suggestions.js +11 -0
  65. package/dist/studio/components/ToolCall.js +33 -0
  66. package/dist/studio/components/WhatsappConnectCard.js +57 -0
  67. package/dist/studio/index.js +42 -0
  68. package/dist/studio/render/json.js +16 -0
  69. package/dist/studio/render/markdown.js +32 -0
  70. package/dist/studio/render/steps.js +58 -0
  71. package/dist/studio/runOneShot.js +96 -0
  72. package/dist/studio/runRepl.js +52 -0
  73. package/dist/studio/slash/handlers.js +199 -0
  74. package/dist/studio/slash/parser.js +46 -0
  75. package/dist/studio/slash/registry.js +16 -0
  76. package/dist/studio/state/store.js +181 -0
  77. package/dist/studio/whatsapp/api.js +63 -0
  78. package/dist/studio/whatsapp/polling.js +77 -0
  79. package/dist/studio/whatsapp/types.js +31 -0
  80. package/dist/types/agent.js +1 -2
  81. package/dist/types/auth.js +1 -2
  82. package/dist/types/common.js +1 -2
  83. package/dist/types/message.js +1 -2
  84. package/dist/types/portal.js +1 -2
  85. package/dist/types/workers.js +1 -2
  86. package/dist/utils/agent-errors.js +46 -0
  87. package/dist/utils/api.js +8 -9
  88. package/dist/utils/banner.js +33 -34
  89. package/dist/utils/credentials.js +12 -20
  90. package/dist/utils/help.js +44 -0
  91. package/dist/utils/logger.js +13 -19
  92. package/dist/utils/ui.js +35 -49
  93. package/package.json +21 -10
  94. package/src/cli.ts +24 -8
  95. package/src/commands/agent/ai-config.ts +89 -34
  96. package/src/commands/agent/chat.ts +49 -37
  97. package/src/commands/agent/copy.ts +19 -13
  98. package/src/commands/agent/create.ts +32 -22
  99. package/src/commands/agent/delete.ts +24 -18
  100. package/src/commands/agent/enable-widget.ts +31 -23
  101. package/src/commands/agent/export.ts +72 -51
  102. package/src/commands/agent/files.ts +51 -39
  103. package/src/commands/agent/get.ts +86 -66
  104. package/src/commands/agent/index.ts +36 -18
  105. package/src/commands/agent/list.ts +22 -16
  106. package/src/commands/agent/monitor.ts +67 -56
  107. package/src/commands/agent/on-message.ts +36 -27
  108. package/src/commands/agent/set.ts +47 -37
  109. package/src/commands/agent/templates.ts +90 -82
  110. package/src/commands/agent/tools.ts +53 -47
  111. package/src/commands/agent/update.ts +28 -20
  112. package/src/commands/agent/validate.ts +135 -0
  113. package/src/commands/agent/wizard.ts +114 -114
  114. package/src/commands/auth/index.ts +3 -3
  115. package/src/commands/auth/login.ts +44 -29
  116. package/src/commands/auth/logout.ts +16 -10
  117. package/src/commands/auth/status.ts +14 -8
  118. package/src/commands/portal/add-agent.ts +23 -17
  119. package/src/commands/portal/add-link.ts +17 -9
  120. package/src/commands/portal/clear-links.ts +13 -7
  121. package/src/commands/portal/create.ts +20 -12
  122. package/src/commands/portal/delete.ts +28 -20
  123. package/src/commands/portal/get.ts +25 -19
  124. package/src/commands/portal/index.ts +22 -10
  125. package/src/commands/portal/list.ts +27 -19
  126. package/src/commands/portal/update.ts +38 -26
  127. package/src/commands/whatsapp/broadcast.ts +28 -18
  128. package/src/commands/whatsapp/channels.ts +31 -20
  129. package/src/commands/whatsapp/chat.ts +20 -12
  130. package/src/commands/whatsapp/connect.ts +39 -31
  131. package/src/commands/whatsapp/delete-webhook.ts +15 -9
  132. package/src/commands/whatsapp/index.ts +24 -10
  133. package/src/commands/whatsapp/register-webhook.ts +16 -10
  134. package/src/commands/whatsapp/send-template.ts +33 -21
  135. package/src/commands/whatsapp/send.ts +23 -15
  136. package/src/commands/whatsapp/widget.ts +25 -17
  137. package/src/commands/workers/deploy.ts +34 -22
  138. package/src/commands/workers/index.ts +21 -7
  139. package/src/commands/workers/list.ts +31 -19
  140. package/src/commands/workers/logs.ts +30 -20
  141. package/src/commands/workers/remove.ts +30 -22
  142. package/src/commands/workers/secret.ts +46 -34
  143. package/src/commands/workers/test.ts +34 -22
  144. package/src/schemas/agent.config.schema.json +569 -0
  145. package/src/studio/api/sseClient.ts +91 -0
  146. package/src/studio/api/studioApi.ts +27 -0
  147. package/src/studio/api/types.ts +96 -0
  148. package/src/studio/components/App.tsx +266 -0
  149. package/src/studio/components/ChatLog.tsx +95 -0
  150. package/src/studio/components/Footer.tsx +38 -0
  151. package/src/studio/components/Header.tsx +39 -0
  152. package/src/studio/components/Input.tsx +32 -0
  153. package/src/studio/components/Message.tsx +87 -0
  154. package/src/studio/components/Suggestions.tsx +26 -0
  155. package/src/studio/components/ToolCall.tsx +58 -0
  156. package/src/studio/components/WhatsappConnectCard.tsx +139 -0
  157. package/src/studio/index.ts +58 -0
  158. package/src/studio/render/markdown.ts +32 -0
  159. package/src/studio/render/steps.ts +57 -0
  160. package/src/studio/runOneShot.ts +114 -0
  161. package/src/studio/runRepl.tsx +76 -0
  162. package/src/studio/slash/handlers.ts +226 -0
  163. package/src/studio/slash/parser.ts +41 -0
  164. package/src/studio/slash/registry.ts +54 -0
  165. package/src/studio/state/store.ts +273 -0
  166. package/src/studio/whatsapp/api.ts +96 -0
  167. package/src/studio/whatsapp/polling.ts +93 -0
  168. package/src/studio/whatsapp/types.ts +80 -0
  169. package/src/types/agent.ts +1 -1
  170. package/src/types/auth.ts +4 -3
  171. package/src/types/portal.ts +1 -1
  172. package/src/types/workers.ts +1 -1
  173. package/src/utils/agent-errors.ts +67 -0
  174. package/src/utils/api.ts +6 -0
  175. package/src/utils/banner.ts +14 -9
  176. package/src/utils/credentials.ts +6 -5
  177. package/src/utils/help.ts +51 -0
  178. package/tsconfig.json +9 -6
@@ -1,8 +1,9 @@
1
1
  import { Command } from 'commander';
2
2
  import { Agent } from 'plazbot';
3
- import { getStoredCredentials } from '../../utils/credentials';
4
- import { logger } from '../../utils/logger';
5
- import { theme } from '../../utils/ui';
3
+ import { getStoredCredentials } from '../../utils/credentials.js';
4
+ import { logger } from '../../utils/logger.js';
5
+ import { addExamples } from '../../utils/help.js';
6
+ import { theme } from '../../utils/ui.js';
6
7
  import chalk from 'chalk';
7
8
  import readline from 'readline';
8
9
  import { HubConnectionBuilder, HttpTransportType, HubConnectionState } from '@microsoft/signalr';
@@ -48,7 +49,7 @@ function getBaseUrl(zone: string, dev: boolean): string {
48
49
  function formatTimestamp(ts: string): string {
49
50
  try {
50
51
  const d = new Date(ts);
51
- return d.toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
52
+ return d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
52
53
  } catch {
53
54
  return ts.substring(11, 19);
54
55
  }
@@ -83,7 +84,7 @@ function renderLogLine(
83
84
 
84
85
  // Separador de sesion
85
86
  if (lastSessionId && log.session_id && log.session_id !== lastSessionId) {
86
- lines.push(dimFn(' ' + '─'.repeat(16) + ' nueva sesion ' + '─'.repeat(16)));
87
+ lines.push(dimFn(' ' + '─'.repeat(16) + ' new session ' + '─'.repeat(16)));
87
88
  }
88
89
 
89
90
  // Linea principal
@@ -100,7 +101,7 @@ function renderLogLine(
100
101
 
101
102
  // Linea de contacto para mensajes
102
103
  if (log.contact_name && (log.event_type === 'msg_in' || log.event_type === 'msg_out')) {
103
- lines.push(dimFn(' | contacto: ') + dimFn(log.contact_name));
104
+ lines.push(dimFn(' | contact: ') + dimFn(log.contact_name));
104
105
  }
105
106
 
106
107
  return lines.join('\n');
@@ -112,20 +113,20 @@ function printHeader(agentName: string) {
112
113
  console.log(
113
114
  chalk.hex('#4CAF50')(' │') +
114
115
  chalk.bold(` Monitor`) +
115
- chalk.hex('#4ade80')(' ● En vivo') +
116
- ' '.repeat(38) +
116
+ chalk.hex('#4ade80')(' ● Live') +
117
+ ' '.repeat(42) +
117
118
  chalk.hex('#4CAF50')('│')
118
119
  );
119
120
  console.log(
120
121
  chalk.hex('#4CAF50')(' │') +
121
- chalk.gray(` Agente: ${truncate(agentName, 44)}`) +
122
- ' '.repeat(Math.max(0, 49 - agentName.length)) +
122
+ chalk.gray(` Agent: ${truncate(agentName, 44)}`) +
123
+ ' '.repeat(Math.max(0, 50 - agentName.length)) +
123
124
  chalk.hex('#4CAF50')('│')
124
125
  );
125
126
  console.log(
126
127
  chalk.hex('#4CAF50')(' │') +
127
- chalk.gray(' Ctrl+C salir | /filter <tipo> | /clear | /help') +
128
- ' '.repeat(12) +
128
+ chalk.gray(' Ctrl+C exit | /filter <type> | /clear | /help') +
129
+ ' '.repeat(13) +
129
130
  chalk.hex('#4CAF50')('│')
130
131
  );
131
132
  console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(62) + '┘'));
@@ -133,31 +134,30 @@ function printHeader(agentName: string) {
133
134
  }
134
135
 
135
136
  const COMMANDS_HELP = `
136
- ${chalk.bold('Comandos disponibles:')}
137
- ${chalk.hex('#4CAF50')('/filter <tipo>')} Toggle filtro por tipo (ej: msg_in, error, tool_call)
138
- ${chalk.hex('#4CAF50')('/filter clear')} Quitar todos los filtros
139
- ${chalk.hex('#4CAF50')('/filters')} Mostrar filtros activos
140
- ${chalk.hex('#4CAF50')('/clear')} Limpiar pantalla
141
- ${chalk.hex('#4CAF50')('/json')} Toggle modo JSON expandido
142
- ${chalk.hex('#4CAF50')('/help')} Mostrar estos comandos
143
-
144
- ${chalk.bold('Tipos de evento:')}
137
+ ${chalk.bold('Available commands:')}
138
+ ${chalk.hex('#4CAF50')('/filter <type>')} Toggle filter by type (e.g. msg_in, error, tool_call)
139
+ ${chalk.hex('#4CAF50')('/filter clear')} Remove all filters
140
+ ${chalk.hex('#4CAF50')('/filters')} Show active filters
141
+ ${chalk.hex('#4CAF50')('/clear')} Clear screen
142
+ ${chalk.hex('#4CAF50')('/json')} Toggle expanded JSON mode
143
+ ${chalk.hex('#4CAF50')('/help')} Show these commands
144
+
145
+ ${chalk.bold('Event types:')}
145
146
  ${Object.entries(EVENT_COLORS).map(([key, val]) =>
146
147
  ` ${chalk.hex(val.color)('●')} ${key}`
147
148
  ).join('\n')}
148
149
  `;
149
150
 
150
151
  export const monitorCommand = new Command('monitor')
151
- .description('Monitor en tiempo real de un agente (logs via SignalR)')
152
- .requiredOption('-a, --agent-id <id>', 'ID del agente')
153
- .option('-f, --filter <types>', 'Filtrar por tipos separados por coma (ej: msg_in,msg_out)')
154
- .option('--no-session', 'Ocultar session ID')
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)')
158
- .option('--dev', 'Usar ambiente de desarrollo', false)
159
- .action(async (options: {
160
- agentId: string;
152
+ .description('Real-time agent monitor (logs via SignalR)')
153
+ .argument('<agentId>', 'Agent ID')
154
+ .option('-f, --filter <types>', 'Filter by comma-separated types (e.g. msg_in,msg_out)')
155
+ .option('--no-session', 'Hide session ID')
156
+ .option('--json', 'Raw JSON mode (for piping)', false)
157
+ .option('-w, --workspace <id>', 'Workspace ID (overrides local config)')
158
+ .option('-z, --zone <zone>', 'Zone LA or EU (overrides local config)')
159
+ .option('--dev', 'Use development environment', false)
160
+ .action(async (agentId: string, options: {
161
161
  filter?: string;
162
162
  session: boolean;
163
163
  json: boolean;
@@ -173,7 +173,7 @@ export const monitorCommand = new Command('monitor')
173
173
  const baseUrl = getBaseUrl(effectiveZone, options.dev);
174
174
 
175
175
  if (options.workspace || options.zone) {
176
- console.log(chalk.hex('#FFA726')(`\n Modo soporte: workspace=${effectiveWorkspace} zona=${effectiveZone}`));
176
+ console.log(chalk.hex('#FFA726')(`\n Support mode: workspace=${effectiveWorkspace} zone=${effectiveZone}`));
177
177
  }
178
178
 
179
179
  // Filtros iniciales
@@ -184,16 +184,16 @@ export const monitorCommand = new Command('monitor')
184
184
  let lastSessionId = '';
185
185
 
186
186
  // Cargar info del agente
187
- let agentName = 'Agente';
187
+ let agentName = 'Agent';
188
188
  try {
189
- process.stdout.write(chalk.gray(' Conectando con agente...'));
189
+ process.stdout.write(chalk.gray(' Connecting to agent...'));
190
190
  const agent = new Agent({
191
191
  workspaceId: effectiveWorkspace,
192
192
  apiKey: credentials.apiKey,
193
193
  zone: effectiveZone,
194
194
  ...(options.dev && { customUrl: 'http://localhost:5090' }),
195
195
  });
196
- const _res: any = await agent.getAgentById({ id: options.agentId });
196
+ const _res: any = await agent.getAgentById({ id: agentId });
197
197
  const info = _res.agent || _res.data || _res;
198
198
  if (info?.name) agentName = info.name;
199
199
  process.stdout.write('\r' + ' '.repeat(40) + '\r');
@@ -234,33 +234,33 @@ export const monitorCommand = new Command('monitor')
234
234
  // Eventos de conexion
235
235
  connection.onreconnecting(() => {
236
236
  if (!jsonMode) {
237
- console.log(chalk.hex('#FFA726')(' ⟳ Reconectando...'));
237
+ console.log(chalk.hex('#FFA726')(' ⟳ Reconnecting...'));
238
238
  }
239
239
  });
240
240
 
241
241
  connection.onreconnected(() => {
242
242
  if (!jsonMode) {
243
- console.log(chalk.hex('#4ade80')(' ● Reconectado'));
243
+ console.log(chalk.hex('#4ade80')(' ● Reconnected'));
244
244
  }
245
- connection.invoke('JoinAgentMonitor', options.agentId).catch(() => {});
245
+ connection.invoke('JoinAgentMonitor', agentId).catch(() => {});
246
246
  });
247
247
 
248
248
  connection.onclose(() => {
249
249
  if (!jsonMode) {
250
- console.log(chalk.hex('#ef4444')(' ● Desconectado'));
250
+ console.log(chalk.hex('#ef4444')(' ● Disconnected'));
251
251
  }
252
252
  });
253
253
 
254
254
  // Iniciar conexion
255
255
  try {
256
256
  await connection.start();
257
- await connection.invoke('JoinAgentMonitor', options.agentId);
257
+ await connection.invoke('JoinAgentMonitor', agentId);
258
258
  if (!jsonMode) {
259
- console.log(chalk.hex('#4ade80')(' ● Conectado al monitor en tiempo real'));
259
+ console.log(chalk.hex('#4ade80')(' ● Connected to real-time monitor'));
260
260
  console.log();
261
261
  }
262
262
  } catch (err) {
263
- logger.error(`No se pudo conectar al monitor: ${err instanceof Error ? err.message : err}`);
263
+ logger.error(`Could not connect to monitor: ${err instanceof Error ? err.message : err}`);
264
264
  process.exit(1);
265
265
  }
266
266
 
@@ -288,15 +288,15 @@ export const monitorCommand = new Command('monitor')
288
288
 
289
289
  if (cmd === '/json') {
290
290
  jsonMode = !jsonMode;
291
- console.log(chalk.gray(` Modo JSON: ${jsonMode ? 'activado' : 'desactivado'}`));
291
+ console.log(chalk.gray(` JSON mode: ${jsonMode ? 'enabled' : 'disabled'}`));
292
292
  return;
293
293
  }
294
294
 
295
295
  if (cmd === '/filters') {
296
296
  if (activeFilters.size === 0) {
297
- console.log(chalk.gray(' Sin filtros activos (mostrando todos)'));
297
+ console.log(chalk.gray(' No active filters (showing all)'));
298
298
  } else {
299
- console.log(chalk.gray(' Filtros activos: ') + chalk.white([...activeFilters].join(', ')));
299
+ console.log(chalk.gray(' Active filters: ') + chalk.white([...activeFilters].join(', ')));
300
300
  }
301
301
  return;
302
302
  }
@@ -304,30 +304,30 @@ export const monitorCommand = new Command('monitor')
304
304
  if (cmd.startsWith('/filter ')) {
305
305
  const filterType = cmd.substring(8).trim();
306
306
  if (!filterType) {
307
- console.log(chalk.gray(' Uso: /filter <tipo> | /filter clear'));
307
+ console.log(chalk.gray(' Usage: /filter <type> | /filter clear'));
308
308
  return;
309
309
  }
310
310
  if (filterType === 'clear') {
311
311
  activeFilters.clear();
312
- console.log(chalk.gray(' Todos los filtros removidos (mostrando todos)'));
312
+ console.log(chalk.gray(' All filters cleared (showing all)'));
313
313
  return;
314
314
  }
315
315
  if (activeFilters.has(filterType)) {
316
316
  activeFilters.delete(filterType);
317
- console.log(chalk.gray(` Filtro removido: ${filterType}`));
317
+ console.log(chalk.gray(` Filter removed: ${filterType}`));
318
318
  } else {
319
319
  activeFilters.add(filterType);
320
320
  const config = EVENT_COLORS[filterType];
321
321
  if (config) {
322
- console.log(chalk.hex(config.color)(` ● Filtro agregado: ${filterType}`));
322
+ console.log(chalk.hex(config.color)(` ● Filter added: ${filterType}`));
323
323
  } else {
324
- console.log(chalk.gray(` Filtro agregado: ${filterType} (tipo desconocido)`));
324
+ console.log(chalk.gray(` Filter added: ${filterType} (unknown type)`));
325
325
  }
326
326
  }
327
327
  if (activeFilters.size > 0) {
328
- console.log(chalk.gray(' Activos: ') + chalk.white([...activeFilters].join(', ')));
328
+ console.log(chalk.gray(' Active: ') + chalk.white([...activeFilters].join(', ')));
329
329
  } else {
330
- console.log(chalk.gray(' Sin filtros (mostrando todos)'));
330
+ console.log(chalk.gray(' No filters (showing all)'));
331
331
  }
332
332
  return;
333
333
  }
@@ -336,11 +336,11 @@ export const monitorCommand = new Command('monitor')
336
336
  // Cierre limpio
337
337
  const cleanup = async () => {
338
338
  if (!jsonMode) {
339
- console.log(chalk.gray('\n Cerrando monitor...'));
339
+ console.log(chalk.gray('\n Closing monitor...'));
340
340
  }
341
341
  try {
342
342
  if (connection.state === HubConnectionState.Connected) {
343
- await connection.invoke('LeaveAgentMonitor', options.agentId);
343
+ await connection.invoke('LeaveAgentMonitor', agentId);
344
344
  }
345
345
  await connection.stop();
346
346
  } catch {
@@ -348,7 +348,7 @@ export const monitorCommand = new Command('monitor')
348
348
  }
349
349
  rl.close();
350
350
  if (!jsonMode) {
351
- console.log(chalk.gray(' Monitor cerrado.\n'));
351
+ console.log(chalk.gray(' Monitor closed.\n'));
352
352
  }
353
353
  process.exit(0);
354
354
  };
@@ -357,8 +357,19 @@ export const monitorCommand = new Command('monitor')
357
357
  process.on('SIGTERM', cleanup);
358
358
 
359
359
  } catch (error) {
360
- const message = error instanceof Error ? error.message : 'Error desconocido';
360
+ const message = error instanceof Error ? error.message : 'Unknown error';
361
361
  logger.error(message);
362
362
  process.exit(1);
363
363
  }
364
364
  });
365
+
366
+ addExamples(monitorCommand, [
367
+ { description: 'Stream every event of an agent in real time',
368
+ command: 'plazbot agent monitor agt_AbcDef123' },
369
+ { description: 'Only show inbound/outbound messages and errors',
370
+ command: 'plazbot agent monitor agt_AbcDef123 -f msg_in,msg_out,error' },
371
+ { description: 'Emit raw JSON (one event per line) for piping to jq',
372
+ command: 'plazbot agent monitor agt_AbcDef123 --json' },
373
+ { description: 'Tail an agent from a different workspace (support mode)',
374
+ command: 'plazbot agent monitor agt_AbcDef123 -w wok_Other123 -z LA' },
375
+ ]);
@@ -1,19 +1,19 @@
1
1
  import { Command } from 'commander';
2
2
  import { Agent } from 'plazbot';
3
- import { getStoredCredentials } from '../../utils/credentials';
4
- import { logger } from '../../utils/logger';
5
- import { AgentCommandOptions, AgentResponse, AgentSource } from '../../types/agent';
3
+ import { getStoredCredentials } from '../../utils/credentials.js';
4
+ import { logger } from '../../utils/logger.js';
5
+ import { addExamples } from '../../utils/help.js';
6
+ import { AgentCommandOptions, AgentResponse, AgentSource } from '../../types/agent.js';
6
7
  import crypto from 'crypto';
7
8
 
8
9
  export const messageCommand = new Command('message')
9
- .description('Envía un mensaje a un agente y obtiene su respuesta')
10
- .requiredOption('-a, --agent-id <id>', 'ID del agente')
11
- .requiredOption('-q, --question <text>', 'Mensaje o pregunta para el agente')
12
- .option('-s, --session-id <id>', 'ID de sesión (opcional)')
13
- .option('-m, --multiple-answers', 'Permitir múltiples respuestas', false)
14
- .option('--dev', 'Usar ambiente de desarrollo', false)
15
- .action(async (options: AgentCommandOptions & {
16
- agentId: string;
10
+ .description('Send a message to an agent and get its response')
11
+ .argument('<agentId>', 'Agent ID')
12
+ .requiredOption('-q, --question <text>', 'Message or question for the agent')
13
+ .option('-s, --session-id <id>', 'Session ID (optional)')
14
+ .option('-m, --multiple-answers', 'Allow multiple answers', false)
15
+ .option('--dev', 'Use development environment', false)
16
+ .action(async (agentId: string, options: AgentCommandOptions & {
17
17
  question: string;
18
18
  sessionId?: string;
19
19
  multipleAnswers?: boolean;
@@ -21,7 +21,7 @@ export const messageCommand = new Command('message')
21
21
  try {
22
22
  // Obtener credenciales guardadas
23
23
  const credentials = await getStoredCredentials();
24
-
24
+
25
25
  const agent = new Agent({
26
26
  workspaceId: credentials.workspace,
27
27
  apiKey: credentials.apiKey,
@@ -32,42 +32,51 @@ export const messageCommand = new Command('message')
32
32
  // Generar un sessionId si no se proporcionó uno
33
33
  const sessionId = options.sessionId || crypto.randomUUID();
34
34
 
35
- logger.title('Enviando mensaje al agente');
36
- logger.label('ID del agente', options.agentId);
37
- logger.label('Pregunta', options.question);
38
- logger.label('ID de sesion', sessionId);
35
+ logger.title('Sending message to agent');
36
+ logger.label('Agent ID', agentId);
37
+ logger.label('Question', options.question);
38
+ logger.label('Session ID', sessionId);
39
39
  if (options.multipleAnswers) {
40
- logger.info('Modo: Múltiples respuestas');
40
+ logger.info('Mode: Multiple answers');
41
41
  }
42
-
42
+
43
43
  const response = await agent.onMessage({
44
- agentId: options.agentId,
44
+ agentId: agentId,
45
45
  question: options.question,
46
46
  sessionId,
47
47
  multipleAnswers: options.multipleAnswers
48
48
  }) as AgentResponse;
49
49
 
50
- logger.title('Respuesta del Agente');
50
+ logger.title('Agent Response');
51
51
  console.log(response.answer);
52
52
 
53
53
  if (response.sources && response.sources.length > 0) {
54
- logger.title('Fuentes');
54
+ logger.title('Sources');
55
55
  response.sources.forEach((source: AgentSource) => {
56
- logger.label('Titulo', source.title || 'Sin titulo');
56
+ logger.label('Title', source.title || 'Untitled');
57
57
  if (source.url) logger.label('URL', source.url);
58
58
  });
59
59
  }
60
60
 
61
- logger.title('Sesion');
61
+ logger.title('Session');
62
62
  logger.label('ID', sessionId);
63
-
63
+
64
64
  if (options.dev) {
65
- logger.warning('\nAmbiente: desarrollo');
65
+ logger.warning('\nEnvironment: development');
66
66
  }
67
67
 
68
68
  } catch (error) {
69
- const message = error instanceof Error ? error.message : 'Error desconocido al enviar el mensaje';
69
+ const message = error instanceof Error ? error.message : 'Unknown error while sending the message';
70
70
  logger.error(message);
71
71
  process.exit(1);
72
72
  }
73
- });
73
+ });
74
+
75
+ addExamples(messageCommand, [
76
+ { description: 'Send a one-shot question to an agent',
77
+ command: 'plazbot agent message agt_AbcDef123 -q "What plans do you offer?"' },
78
+ { description: 'Continue an existing session',
79
+ command: 'plazbot agent message agt_AbcDef123 -q "And the price?" -s sess_AbcDef123' },
80
+ { description: 'Allow multiple answers per turn',
81
+ command: 'plazbot agent message agt_AbcDef123 -q "Tell me everything" -m' },
82
+ ]);
@@ -1,20 +1,30 @@
1
1
  import { Command } from 'commander';
2
2
  import { Agent } from 'plazbot';
3
3
  import inquirer from 'inquirer';
4
- import { getStoredCredentials } from '../../utils/credentials';
5
- import { logger } from '../../utils/logger';
6
- import { createSpinner, theme, section, kvPair } from '../../utils/ui';
7
- import { AgentCommandOptions } from '../../types/agent';
4
+ import { getStoredCredentials } from '../../utils/credentials.js';
5
+ import { logger } from '../../utils/logger.js';
6
+ import { addExamples } from '../../utils/help.js';
7
+ import { createSpinner, theme, section, kvPair } from '../../utils/ui.js';
8
+ import { AgentCommandOptions } from '../../types/agent.js';
8
9
 
9
10
  const setGroup = new Command('set')
10
- .description('Configurar rapidamente propiedades del agente');
11
+ .description('Quickly configure agent properties');
12
+
13
+ addExamples(setGroup, [
14
+ { description: 'Replace the agent greeting',
15
+ command: 'plazbot agent set greeting agt_AbcDef123 "Hi! How can I help you today?"' },
16
+ { description: 'Configure tone, style, language, etc. interactively',
17
+ command: 'plazbot agent set instructions agt_AbcDef123' },
18
+ { description: 'Define the agent persona (name, role, voice)',
19
+ command: 'plazbot agent set persona agt_AbcDef123' },
20
+ ]);
11
21
 
12
22
  // Set greeting
13
23
  setGroup.command('greeting')
14
- .description('Cambiar el saludo del agente')
15
- .argument('<agentId>', 'ID del agente')
16
- .argument('<greeting>', 'Nuevo saludo')
17
- .option('--dev', 'Usar ambiente de desarrollo', false)
24
+ .description('Change the agent greeting')
25
+ .argument('<agentId>', 'Agent ID')
26
+ .argument('<greeting>', 'New greeting')
27
+ .option('--dev', 'Use development environment', false)
18
28
  .action(async (agentId: string, greeting: string, options: AgentCommandOptions) => {
19
29
  try {
20
30
  const credentials = await getStoredCredentials();
@@ -25,14 +35,14 @@ setGroup.command('greeting')
25
35
  ...(options.dev && { customUrl: "http://localhost:5090" })
26
36
  });
27
37
 
28
- const spinner = createSpinner('Actualizando saludo...');
38
+ const spinner = createSpinner('Updating greeting...');
29
39
  spinner.start();
30
40
  await agent.setGreeting(agentId, greeting);
31
- spinner.succeed('Saludo actualizado');
32
- logger.label('Nuevo saludo', greeting);
41
+ spinner.succeed('Greeting updated');
42
+ logger.label('New greeting', greeting);
33
43
 
34
44
  } catch (error) {
35
- const message = error instanceof Error ? error.message : 'Error desconocido';
45
+ const message = error instanceof Error ? error.message : 'Unknown error';
36
46
  logger.error(message);
37
47
  process.exit(1);
38
48
  }
@@ -40,9 +50,9 @@ setGroup.command('greeting')
40
50
 
41
51
  // Set instructions (wizard)
42
52
  setGroup.command('instructions')
43
- .description('Configurar instrucciones del agente')
44
- .argument('<agentId>', 'ID del agente')
45
- .option('--dev', 'Usar ambiente de desarrollo', false)
53
+ .description('Configure agent instructions')
54
+ .argument('<agentId>', 'Agent ID')
55
+ .option('--dev', 'Use development environment', false)
46
56
  .action(async (agentId: string, options: AgentCommandOptions) => {
47
57
  try {
48
58
  const credentials = await getStoredCredentials();
@@ -54,22 +64,22 @@ setGroup.command('instructions')
54
64
  });
55
65
 
56
66
  // Cargar instrucciones actuales
57
- const loadSpinner = createSpinner('Cargando...');
67
+ const loadSpinner = createSpinner('Loading...');
58
68
  loadSpinner.start();
59
69
  const _res1: any = await agent.getAgentById({ id: agentId });
60
70
  const agentData = _res1.agent || _res1.data || _res1;
61
71
  loadSpinner.stop();
62
72
 
63
73
  const current = agentData.instructions || {};
64
- console.log(section('Instrucciones - ' + (agentData.name || agentId)));
74
+ console.log(section('Instructions - ' + (agentData.name || agentId)));
65
75
 
66
76
  const answers = await (inquirer as any).prompt([
67
- { type: 'list', name: 'tone', message: 'Tono:', choices: ['profesional', 'amigable', 'formal', 'casual', 'tecnico', 'empatico'], default: current.tone || 'profesional' },
68
- { type: 'list', name: 'style', message: 'Estilo:', choices: ['conciso', 'detallado', 'conversacional', 'directo'], default: current.style || 'conciso' },
69
- { type: 'input', name: 'personality', message: 'Personalidad:', default: current.personality || '' },
70
- { type: 'input', name: 'objective', message: 'Objetivo:', default: current.objective || '' },
71
- { type: 'list', name: 'language', message: 'Idioma:', choices: ['Espanol', 'English', 'Portugues'], default: current.language || 'Espanol' },
72
- { type: 'confirm', name: 'emojis', message: 'Usar emojis?', default: current.emojis === true },
77
+ { type: 'list', name: 'tone', message: 'Tone:', choices: ['profesional', 'amigable', 'formal', 'casual', 'tecnico', 'empatico'], default: current.tone || 'profesional' },
78
+ { type: 'list', name: 'style', message: 'Style:', choices: ['conciso', 'detallado', 'conversacional', 'directo'], default: current.style || 'conciso' },
79
+ { type: 'input', name: 'personality', message: 'Personality:', default: current.personality || '' },
80
+ { type: 'input', name: 'objective', message: 'Objective:', default: current.objective || '' },
81
+ { type: 'list', name: 'language', message: 'Language:', choices: ['Espanol', 'English', 'Portugues'], default: current.language || 'Espanol' },
82
+ { type: 'confirm', name: 'emojis', message: 'Use emojis?', default: current.emojis === true },
73
83
  ]);
74
84
 
75
85
  const instructions = {
@@ -82,13 +92,13 @@ setGroup.command('instructions')
82
92
  emojis: answers.emojis,
83
93
  };
84
94
 
85
- const spinner = createSpinner('Guardando instrucciones...');
95
+ const spinner = createSpinner('Saving instructions...');
86
96
  spinner.start();
87
97
  await agent.setInstructions(agentId, instructions);
88
- spinner.succeed('Instrucciones actualizadas');
98
+ spinner.succeed('Instructions updated');
89
99
 
90
100
  } catch (error) {
91
- const message = error instanceof Error ? error.message : 'Error desconocido';
101
+ const message = error instanceof Error ? error.message : 'Unknown error';
92
102
  logger.error(message);
93
103
  process.exit(1);
94
104
  }
@@ -96,9 +106,9 @@ setGroup.command('instructions')
96
106
 
97
107
  // Set persona (wizard)
98
108
  setGroup.command('persona')
99
- .description('Configurar la persona del agente')
100
- .argument('<agentId>', 'ID del agente')
101
- .option('--dev', 'Usar ambiente de desarrollo', false)
109
+ .description('Configure the agent persona')
110
+ .argument('<agentId>', 'Agent ID')
111
+ .option('--dev', 'Use development environment', false)
102
112
  .action(async (agentId: string, options: AgentCommandOptions) => {
103
113
  try {
104
114
  const credentials = await getStoredCredentials();
@@ -109,7 +119,7 @@ setGroup.command('persona')
109
119
  ...(options.dev && { customUrl: "http://localhost:5090" })
110
120
  });
111
121
 
112
- const loadSpinner = createSpinner('Cargando...');
122
+ const loadSpinner = createSpinner('Loading...');
113
123
  loadSpinner.start();
114
124
  const _res2: any = await agent.getAgentById({ id: agentId });
115
125
  const agentData = _res2.agent || _res2.data || _res2;
@@ -119,18 +129,18 @@ setGroup.command('persona')
119
129
  console.log(section('Persona - ' + (agentData.name || agentId)));
120
130
 
121
131
  const answers = await (inquirer as any).prompt([
122
- { type: 'input', name: 'name', message: 'Nombre del personaje:', default: current.name || '' },
123
- { type: 'input', name: 'role', message: 'Rol:', default: current.role || '' },
124
- { type: 'confirm', name: 'speaksInFirstPerson', message: 'Hablar en primera persona?', default: current.speaksInFirstPerson !== false },
132
+ { type: 'input', name: 'name', message: 'Character name:', default: current.name || '' },
133
+ { type: 'input', name: 'role', message: 'Role:', default: current.role || '' },
134
+ { type: 'confirm', name: 'speaksInFirstPerson', message: 'Speak in first person?', default: current.speaksInFirstPerson !== false },
125
135
  ]);
126
136
 
127
- const spinner = createSpinner('Guardando persona...');
137
+ const spinner = createSpinner('Saving persona...');
128
138
  spinner.start();
129
139
  await agent.setPersona(agentId, answers);
130
- spinner.succeed('Persona actualizada');
140
+ spinner.succeed('Persona updated');
131
141
 
132
142
  } catch (error) {
133
- const message = error instanceof Error ? error.message : 'Error desconocido';
143
+ const message = error instanceof Error ? error.message : 'Unknown error';
134
144
  logger.error(message);
135
145
  process.exit(1);
136
146
  }