plazbot-cli 0.2.25 → 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 +59 -55
  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 +48 -36
  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,18 +1,13 @@
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.crossCopyCommand = exports.exportCommand = 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 ui_1 = require("../../utils/ui");
12
- const chalk_1 = __importDefault(require("chalk"));
13
- const fs_1 = __importDefault(require("fs"));
14
- const path_1 = __importDefault(require("path"));
15
- const inquirer_1 = __importDefault(require("inquirer"));
1
+ import { Command } from 'commander';
2
+ import { Agent } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials.js';
4
+ import { logger } from '../../utils/logger.js';
5
+ import { addExamples } from '../../utils/help.js';
6
+ import { createSpinner } from '../../utils/ui.js';
7
+ import chalk from 'chalk';
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import inquirer from 'inquirer';
16
11
  // Campos validos segun el schema de agentValidation.ts (additionalProperties: false)
17
12
  const VALID_AGENT_FIELDS = new Set([
18
13
  'name', 'description', 'prompt', 'zone', 'timezone', 'buffer',
@@ -184,34 +179,34 @@ function cleanAgentForExport(agentData) {
184
179
  }
185
180
  return cleaned;
186
181
  }
187
- exports.exportCommand = new commander_1.Command('export')
188
- .description('Exportar configuracion limpia de un agente (compatible con importacion)')
189
- .argument('<agentId>', 'ID del agente a exportar')
190
- .option('-w, --workspace <id>', 'Workspace ID origen (sobreescribe config local)')
191
- .option('-z, --zone <zone>', 'Zona LA o EU (sobreescribe config local)')
192
- .option('-o, --output <path>', 'Ruta del archivo de salida (.json)')
193
- .option('--no-channels', 'Excluir canales de la exportacion')
194
- .option('--no-ai', 'Excluir configuracion de IA personalizada')
195
- .option('--dev', 'Usar ambiente de desarrollo', false)
182
+ export const exportCommand = new Command('export')
183
+ .description('Export a clean agent configuration (compatible with import)')
184
+ .argument('<agentId>', 'Agent ID to export')
185
+ .option('-w, --workspace <id>', 'Source workspace ID (overrides local config)')
186
+ .option('-z, --zone <zone>', 'Zone LA or EU (overrides local config)')
187
+ .option('-o, --output <path>', 'Output file path (.json)')
188
+ .option('--no-channels', 'Exclude channels from export')
189
+ .option('--no-ai', 'Exclude custom AI configuration')
190
+ .option('--dev', 'Use development environment', false)
196
191
  .action(async (agentId, options) => {
197
192
  try {
198
- const credentials = await (0, credentials_1.getStoredCredentials)();
193
+ const credentials = await getStoredCredentials();
199
194
  const effectiveWorkspace = options.workspace || credentials.workspace;
200
195
  const effectiveZone = (options.zone?.toUpperCase() === 'EU' ? 'EU' : options.zone?.toUpperCase() === 'LA' ? 'LA' : credentials.zone);
201
196
  if (options.workspace || options.zone) {
202
- console.log(chalk_1.default.hex('#FFA726')(`\n Modo soporte: workspace=${effectiveWorkspace} zona=${effectiveZone}`));
197
+ console.log(chalk.hex('#FFA726')(`\n Support mode: workspace=${effectiveWorkspace} zone=${effectiveZone}`));
203
198
  }
204
- const agent = new plazbot_1.Agent({
199
+ const agent = new Agent({
205
200
  workspaceId: effectiveWorkspace,
206
201
  apiKey: credentials.apiKey,
207
202
  zone: effectiveZone,
208
203
  ...(options.dev && { customUrl: 'http://localhost:5090' }),
209
204
  });
210
- const spinner = (0, ui_1.createSpinner)('Obteniendo agente...');
205
+ const spinner = createSpinner('Fetching agent...');
211
206
  spinner.start();
212
207
  const response = await agent.getAgentById({ id: agentId });
213
208
  const agentData = response.agent || response.data || response;
214
- spinner.succeed('Agente obtenido');
209
+ spinner.succeed('Agent fetched');
215
210
  // Limpiar para exportacion
216
211
  const cleaned = cleanAgentForExport(agentData);
217
212
  // Aplicar opciones de exclusion
@@ -225,54 +220,64 @@ exports.exportCommand = new commander_1.Command('export')
225
220
  const jsonOutput = JSON.stringify(cleaned, null, 2);
226
221
  // Guardar en archivo o mostrar en consola
227
222
  if (options.output) {
228
- const outputPath = path_1.default.resolve(options.output);
229
- fs_1.default.writeFileSync(outputPath, jsonOutput, 'utf-8');
230
- console.log(chalk_1.default.hex('#4ade80')(`\n Exportado a: ${outputPath}`));
223
+ const outputPath = path.resolve(options.output);
224
+ fs.writeFileSync(outputPath, jsonOutput, 'utf-8');
225
+ console.log(chalk.hex('#4ade80')(`\n Exported to: ${outputPath}`));
231
226
  }
232
227
  else {
233
228
  console.log();
234
229
  console.log(jsonOutput);
235
230
  }
236
231
  console.log();
237
- console.log(chalk_1.default.gray(' Este JSON es compatible con:'));
238
- console.log(chalk_1.default.gray(' - plazbot agent create <archivo.json>'));
239
- console.log(chalk_1.default.gray(' - Importar JSON en la plataforma (AgentTraining)'));
232
+ console.log(chalk.gray(' This JSON is compatible with:'));
233
+ console.log(chalk.gray(' - plazbot agent create <file.json>'));
234
+ console.log(chalk.gray(' - Importing JSON in the platform (AgentTraining)'));
240
235
  console.log();
241
236
  }
242
237
  catch (error) {
243
- const message = error instanceof Error ? error.message : 'Error desconocido';
244
- logger_1.logger.error(message);
238
+ const message = error instanceof Error ? error.message : 'Unknown error';
239
+ logger.error(message);
245
240
  process.exit(1);
246
241
  }
247
242
  });
248
- exports.crossCopyCommand = new commander_1.Command('cross-copy')
249
- .description('Copiar un agente de un workspace a otro')
250
- .argument('<agentId>', 'ID del agente a copiar')
251
- .requiredOption('--from-workspace <id>', 'Workspace ID de origen')
252
- .requiredOption('--to-workspace <id>', 'Workspace ID de destino')
253
- .option('--from-zone <zone>', 'Zona del workspace origen (LA o EU)', 'LA')
254
- .option('--to-zone <zone>', 'Zona del workspace destino (LA o EU)', 'LA')
255
- .option('--no-channels', 'No copiar canales (recomendado)')
256
- .option('--no-ai', 'No copiar configuracion de IA personalizada')
257
- .option('--dev', 'Usar ambiente de desarrollo', false)
243
+ addExamples(exportCommand, [
244
+ { description: 'Print the cleaned JSON to stdout',
245
+ command: 'plazbot agent export agt_AbcDef123' },
246
+ { description: 'Write the cleaned JSON to a file',
247
+ command: 'plazbot agent export agt_AbcDef123 -o ./agent.json' },
248
+ { description: 'Export without channels nor AI credentials (portable JSON)',
249
+ command: 'plazbot agent export agt_AbcDef123 -o ./agent.json --no-channels --no-ai' },
250
+ { description: 'Export from a different workspace (support mode)',
251
+ command: 'plazbot agent export agt_AbcDef123 -w wok_Other123 -z LA -o ./agent.json' },
252
+ ]);
253
+ export const crossCopyCommand = new Command('cross-copy')
254
+ .description('Copy an agent from one workspace to another')
255
+ .argument('<agentId>', 'Agent ID to copy')
256
+ .requiredOption('--from-workspace <id>', 'Source workspace ID')
257
+ .requiredOption('--to-workspace <id>', 'Target workspace ID')
258
+ .option('--from-zone <zone>', 'Source workspace zone (LA or EU)', 'LA')
259
+ .option('--to-zone <zone>', 'Target workspace zone (LA or EU)', 'LA')
260
+ .option('--no-channels', 'Do not copy channels (recommended)')
261
+ .option('--no-ai', 'Do not copy custom AI configuration')
262
+ .option('--dev', 'Use development environment', false)
258
263
  .action(async (agentId, options) => {
259
264
  try {
260
- const credentials = await (0, credentials_1.getStoredCredentials)();
265
+ const credentials = await getStoredCredentials();
261
266
  const fromZone = (options.fromZone.toUpperCase() === 'EU' ? 'EU' : 'LA');
262
267
  const toZone = (options.toZone.toUpperCase() === 'EU' ? 'EU' : 'LA');
263
268
  console.log();
264
- console.log(chalk_1.default.hex('#4CAF50')(' ┌' + '─'.repeat(58) + '┐'));
265
- console.log(chalk_1.default.hex('#4CAF50')(' │') + chalk_1.default.bold(' Copiar agente entre workspaces').padEnd(68) + chalk_1.default.hex('#4CAF50')('│'));
266
- console.log(chalk_1.default.hex('#4CAF50')(' └' + '─'.repeat(58) + '┘'));
269
+ console.log(chalk.hex('#4CAF50')(' ┌' + '─'.repeat(58) + '┐'));
270
+ console.log(chalk.hex('#4CAF50')(' │') + chalk.bold(' Copy agent between workspaces').padEnd(68) + chalk.hex('#4CAF50')('│'));
271
+ console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(58) + '┘'));
267
272
  console.log();
268
- console.log(chalk_1.default.gray(` Origen: ${options.fromWorkspace} (${fromZone})`));
269
- console.log(chalk_1.default.gray(` Destino: ${options.toWorkspace} (${toZone})`));
270
- console.log(chalk_1.default.gray(` Agente: ${agentId}`));
273
+ console.log(chalk.gray(` Source: ${options.fromWorkspace} (${fromZone})`));
274
+ console.log(chalk.gray(` Target: ${options.toWorkspace} (${toZone})`));
275
+ console.log(chalk.gray(` Agent: ${agentId}`));
271
276
  console.log();
272
277
  // 1. Obtener agente del workspace origen
273
- const spinnerGet = (0, ui_1.createSpinner)('Obteniendo agente del workspace origen...');
278
+ const spinnerGet = createSpinner('Fetching agent from source workspace...');
274
279
  spinnerGet.start();
275
- const sourceAgent = new plazbot_1.Agent({
280
+ const sourceAgent = new Agent({
276
281
  workspaceId: options.fromWorkspace,
277
282
  apiKey: credentials.apiKey,
278
283
  zone: fromZone,
@@ -281,10 +286,10 @@ exports.crossCopyCommand = new commander_1.Command('cross-copy')
281
286
  const response = await sourceAgent.getAgentById({ id: agentId });
282
287
  const agentData = response.agent || response.data || response;
283
288
  if (!agentData || !agentData.name) {
284
- spinnerGet.fail('No se encontro el agente en el workspace origen');
289
+ spinnerGet.fail('Agent not found in source workspace');
285
290
  process.exit(1);
286
291
  }
287
- spinnerGet.succeed(`Agente obtenido: ${agentData.name}`);
292
+ spinnerGet.succeed(`Agent fetched: ${agentData.name}`);
288
293
  // 2. Limpiar JSON
289
294
  const cleaned = cleanAgentForExport(agentData);
290
295
  // Ajustar zona al destino
@@ -302,28 +307,28 @@ exports.crossCopyCommand = new commander_1.Command('cross-copy')
302
307
  cleaned.enableWidget = false;
303
308
  // 3. Mostrar resumen
304
309
  console.log();
305
- console.log(chalk_1.default.bold(' Configuracion a copiar:'));
306
- console.log(chalk_1.default.gray(` Nombre: ${cleaned.name}`));
307
- console.log(chalk_1.default.gray(` Zona destino: ${cleaned.zone}`));
308
- console.log(chalk_1.default.gray(` Canales: ${cleaned.channels?.length || 0}`));
309
- console.log(chalk_1.default.gray(` Servicios: ${cleaned.services?.length || 0}`));
310
- console.log(chalk_1.default.gray(` Acciones: ${cleaned.actions?.length || 0}`));
311
- console.log(chalk_1.default.gray(` AI Custom: ${cleaned.customAIConfig ? 'Si' : 'No'}`));
310
+ console.log(chalk.bold(' Configuration to copy:'));
311
+ console.log(chalk.gray(` Name: ${cleaned.name}`));
312
+ console.log(chalk.gray(` Target zone: ${cleaned.zone}`));
313
+ console.log(chalk.gray(` Channels: ${cleaned.channels?.length || 0}`));
314
+ console.log(chalk.gray(` Services: ${cleaned.services?.length || 0}`));
315
+ console.log(chalk.gray(` Actions: ${cleaned.actions?.length || 0}`));
316
+ console.log(chalk.gray(` Custom AI: ${cleaned.customAIConfig ? 'Yes' : 'No'}`));
312
317
  console.log();
313
- const { confirm } = await inquirer_1.default.prompt([{
318
+ const { confirm } = await inquirer.prompt([{
314
319
  type: 'confirm',
315
320
  name: 'confirm',
316
- message: 'Crear este agente en el workspace destino?',
321
+ message: 'Create this agent in the target workspace?',
317
322
  default: true,
318
323
  }]);
319
324
  if (!confirm) {
320
- console.log(chalk_1.default.gray(' Operacion cancelada.'));
325
+ console.log(chalk.gray(' Operation cancelled.'));
321
326
  return;
322
327
  }
323
328
  // 4. Crear en workspace destino
324
- const spinnerCreate = (0, ui_1.createSpinner)('Creando agente en workspace destino...');
329
+ const spinnerCreate = createSpinner('Creating agent in target workspace...');
325
330
  spinnerCreate.start();
326
- const targetAgent = new plazbot_1.Agent({
331
+ const targetAgent = new Agent({
327
332
  workspaceId: options.toWorkspace,
328
333
  apiKey: credentials.apiKey,
329
334
  zone: toZone,
@@ -331,22 +336,30 @@ exports.crossCopyCommand = new commander_1.Command('cross-copy')
331
336
  });
332
337
  const result = await targetAgent.addAgent(cleaned);
333
338
  if (result?.success === false) {
334
- spinnerCreate.fail(`Error: ${result.message || 'No se pudo crear el agente'}`);
339
+ spinnerCreate.fail(`Error: ${result.message || 'Could not create the agent'}`);
335
340
  process.exit(1);
336
341
  }
337
342
  const newId = result?.agentId || result?.id || result?.data?.agentId;
338
- spinnerCreate.succeed('Agente creado exitosamente');
343
+ spinnerCreate.succeed('Agent created successfully');
339
344
  console.log();
340
345
  if (newId) {
341
- console.log(chalk_1.default.hex('#4ade80')(` Nuevo ID: ${newId}`));
346
+ console.log(chalk.hex('#4ade80')(` New ID: ${newId}`));
342
347
  }
343
- console.log(chalk_1.default.gray(' Widget deshabilitado por defecto.'));
344
- console.log(chalk_1.default.gray(' Canales deben configurarse manualmente en el workspace destino.'));
348
+ console.log(chalk.gray(' Widget disabled by default.'));
349
+ console.log(chalk.gray(' Channels must be configured manually in the target workspace.'));
345
350
  console.log();
346
351
  }
347
352
  catch (error) {
348
- const message = error instanceof Error ? error.message : 'Error desconocido';
349
- logger_1.logger.error(message);
353
+ const message = error instanceof Error ? error.message : 'Unknown error';
354
+ logger.error(message);
350
355
  process.exit(1);
351
356
  }
352
357
  });
358
+ addExamples(crossCopyCommand, [
359
+ { description: 'Copy an agent between two LA workspaces (skip channels)',
360
+ command: 'plazbot agent cross-copy agt_AbcDef123 --from-workspace wok_Source123 --to-workspace wok_Target456' },
361
+ { description: 'Copy across zones (LA → EU)',
362
+ command: 'plazbot agent cross-copy agt_AbcDef123 --from-workspace wok_Source123 --from-zone LA --to-workspace wok_Target456 --to-zone EU' },
363
+ { description: 'Copy preserving channels and AI providers',
364
+ command: 'plazbot agent cross-copy agt_AbcDef123 --from-workspace wok_Source123 --to-workspace wok_Target456 --channels --ai' },
365
+ ]);
@@ -1,70 +1,78 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filesCommand = 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
- const filesGroup = new commander_1.Command('files')
10
- .description('Gestionar archivos de la base de conocimiento del agente');
1
+ import { Command } from 'commander';
2
+ import { Agent } from 'plazbot';
3
+ import { getStoredCredentials } from '../../utils/credentials.js';
4
+ import { logger } from '../../utils/logger.js';
5
+ import { addExamples } from '../../utils/help.js';
6
+ import { createSpinner, createTable, theme, section } from '../../utils/ui.js';
7
+ const filesGroup = new Command('files')
8
+ .description('Manage files in the agent knowledge base');
9
+ addExamples(filesGroup, [
10
+ { description: 'List the knowledge-base files of an agent',
11
+ command: 'plazbot agent files list agt_AbcDef123' },
12
+ { description: 'Add a remote PDF/DOC to the knowledge base',
13
+ command: 'plazbot agent files add agt_AbcDef123 -u https://files.example.com/manual.pdf -r manual -t docs,onboarding' },
14
+ { description: 'Check whether a file finished processing',
15
+ command: 'plazbot agent files status file_AbcDef123' },
16
+ { description: 'Remove a file from the knowledge base',
17
+ command: 'plazbot agent files delete agt_AbcDef123 file_AbcDef123' },
18
+ ]);
11
19
  // Listar archivos
12
20
  filesGroup.command('list')
13
- .description('Listar archivos del agente')
14
- .argument('<agentId>', 'ID del agente')
15
- .option('--dev', 'Usar ambiente de desarrollo', false)
21
+ .description('List agent files')
22
+ .argument('<agentId>', 'Agent ID')
23
+ .option('--dev', 'Use development environment', false)
16
24
  .action(async (agentId, options) => {
17
25
  try {
18
- const credentials = await (0, credentials_1.getStoredCredentials)();
19
- const agent = new plazbot_1.Agent({
26
+ const credentials = await getStoredCredentials();
27
+ const agent = new Agent({
20
28
  workspaceId: credentials.workspace,
21
29
  apiKey: credentials.apiKey,
22
30
  zone: credentials.zone,
23
31
  ...(options.dev && { customUrl: "http://localhost:5090" })
24
32
  });
25
- const spinner = (0, ui_1.createSpinner)('Cargando archivos...');
33
+ const spinner = createSpinner('Loading files...');
26
34
  spinner.start();
27
35
  const _res = await agent.getAgentById({ id: agentId });
28
36
  const agentData = _res.agent || _res.data || _res;
29
37
  spinner.stop();
30
38
  const files = agentData.files || [];
31
- console.log((0, ui_1.section)('Archivos - ' + (agentData.name || agentId)));
39
+ console.log(section('Files - ' + (agentData.name || agentId)));
32
40
  if (files.length === 0) {
33
- console.log(ui_1.theme.muted('\n No hay archivos en la base de conocimiento'));
34
- console.log(ui_1.theme.muted(' Usa: plazbot agent files add <agentId> --url <url>\n'));
41
+ console.log(theme.muted('\n No files in the knowledge base'));
42
+ console.log(theme.muted(' Use: plazbot agent files add <agentId> --url <url>\n'));
35
43
  return;
36
44
  }
37
45
  const rows = files.map((f) => [
38
46
  f.fileId || f.id || 'N/A',
39
- f.name || f.reference || 'Sin nombre',
47
+ f.name || f.reference || 'Untitled',
40
48
  (f.tags || []).join(', ') || '-',
41
49
  ]);
42
- console.log((0, ui_1.createTable)(['ID', 'Nombre', 'Tags'], rows));
50
+ console.log(createTable(['ID', 'Name', 'Tags'], rows));
43
51
  }
44
52
  catch (error) {
45
- const message = error instanceof Error ? error.message : 'Error desconocido';
46
- logger_1.logger.error(message);
53
+ const message = error instanceof Error ? error.message : 'Unknown error';
54
+ logger.error(message);
47
55
  process.exit(1);
48
56
  }
49
57
  });
50
58
  // Agregar archivo
51
59
  filesGroup.command('add')
52
- .description('Agregar archivo a la base de conocimiento')
53
- .argument('<agentId>', 'ID del agente')
54
- .requiredOption('-u, --url <url>', 'URL del archivo (PDF, DOC, DOCX)')
55
- .option('-r, --reference <name>', 'Nombre de referencia', 'documento')
56
- .option('-t, --tags <tags>', 'Tags separados por coma', '')
57
- .option('--dev', 'Usar ambiente de desarrollo', false)
60
+ .description('Add a file to the knowledge base')
61
+ .argument('<agentId>', 'Agent ID')
62
+ .requiredOption('-u, --url <url>', 'File URL (PDF, DOC, DOCX)')
63
+ .option('-r, --reference <name>', 'Reference name', 'documento')
64
+ .option('-t, --tags <tags>', 'Comma-separated tags', '')
65
+ .option('--dev', 'Use development environment', false)
58
66
  .action(async (agentId, options) => {
59
67
  try {
60
- const credentials = await (0, credentials_1.getStoredCredentials)();
61
- const agent = new plazbot_1.Agent({
68
+ const credentials = await getStoredCredentials();
69
+ const agent = new Agent({
62
70
  workspaceId: credentials.workspace,
63
71
  apiKey: credentials.apiKey,
64
72
  zone: credentials.zone,
65
73
  ...(options.dev && { customUrl: "http://localhost:5090" })
66
74
  });
67
- const spinner = (0, ui_1.createSpinner)('Subiendo archivo...');
75
+ const spinner = createSpinner('Uploading file...');
68
76
  spinner.start();
69
77
  const tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : [];
70
78
  const result = await agent.addFile({
@@ -73,71 +81,71 @@ filesGroup.command('add')
73
81
  agentId,
74
82
  tags,
75
83
  });
76
- spinner.succeed('Archivo agregado');
84
+ spinner.succeed('File added');
77
85
  if (result?.fileId) {
78
- logger_1.logger.label('File ID', result.fileId);
79
- logger_1.logger.dim('El archivo esta siendo procesado. Verifica con:');
80
- logger_1.logger.dim(`plazbot agent files status ${result.fileId}`);
86
+ logger.label('File ID', result.fileId);
87
+ logger.dim('The file is being processed. Check status with:');
88
+ logger.dim(`plazbot agent files status ${result.fileId}`);
81
89
  }
82
90
  }
83
91
  catch (error) {
84
- const message = error instanceof Error ? error.message : 'Error desconocido';
85
- logger_1.logger.error(message);
92
+ const message = error instanceof Error ? error.message : 'Unknown error';
93
+ logger.error(message);
86
94
  process.exit(1);
87
95
  }
88
96
  });
89
97
  // Verificar estado
90
98
  filesGroup.command('status')
91
- .description('Verificar estado de procesamiento de un archivo')
92
- .argument('<fileId>', 'ID del archivo')
93
- .option('--dev', 'Usar ambiente de desarrollo', false)
99
+ .description('Check the processing status of a file')
100
+ .argument('<fileId>', 'File ID')
101
+ .option('--dev', 'Use development environment', false)
94
102
  .action(async (fileId, options) => {
95
103
  try {
96
- const credentials = await (0, credentials_1.getStoredCredentials)();
97
- const agent = new plazbot_1.Agent({
104
+ const credentials = await getStoredCredentials();
105
+ const agent = new Agent({
98
106
  workspaceId: credentials.workspace,
99
107
  apiKey: credentials.apiKey,
100
108
  zone: credentials.zone,
101
109
  ...(options.dev && { customUrl: "http://localhost:5090" })
102
110
  });
103
- const spinner = (0, ui_1.createSpinner)('Verificando...');
111
+ const spinner = createSpinner('Checking...');
104
112
  spinner.start();
105
113
  const result = await agent.validateFile({ fileId });
106
114
  spinner.stop();
107
- logger_1.logger.title('Estado del archivo');
108
- logger_1.logger.label('File ID', fileId);
109
- logger_1.logger.label('Estado', result?.status ? 'Completado' : 'En proceso');
115
+ logger.title('File status');
116
+ logger.label('File ID', fileId);
117
+ logger.label('Status', result?.status ? 'Completed' : 'Processing');
110
118
  }
111
119
  catch (error) {
112
- const message = error instanceof Error ? error.message : 'Error desconocido';
113
- logger_1.logger.error(message);
120
+ const message = error instanceof Error ? error.message : 'Unknown error';
121
+ logger.error(message);
114
122
  process.exit(1);
115
123
  }
116
124
  });
117
125
  // Eliminar archivo
118
126
  filesGroup.command('delete')
119
- .description('Eliminar archivo de la base de conocimiento')
120
- .argument('<agentId>', 'ID del agente')
121
- .argument('<fileId>', 'ID del archivo')
122
- .option('--dev', 'Usar ambiente de desarrollo', false)
127
+ .description('Delete a file from the knowledge base')
128
+ .argument('<agentId>', 'Agent ID')
129
+ .argument('<fileId>', 'File ID')
130
+ .option('--dev', 'Use development environment', false)
123
131
  .action(async (agentId, fileId, options) => {
124
132
  try {
125
- const credentials = await (0, credentials_1.getStoredCredentials)();
126
- const agent = new plazbot_1.Agent({
133
+ const credentials = await getStoredCredentials();
134
+ const agent = new Agent({
127
135
  workspaceId: credentials.workspace,
128
136
  apiKey: credentials.apiKey,
129
137
  zone: credentials.zone,
130
138
  ...(options.dev && { customUrl: "http://localhost:5090" })
131
139
  });
132
- const spinner = (0, ui_1.createSpinner)('Eliminando archivo...');
140
+ const spinner = createSpinner('Deleting file...');
133
141
  spinner.start();
134
142
  await agent.deleteFile({ fileId, agentId });
135
- spinner.succeed('Archivo eliminado');
143
+ spinner.succeed('File deleted');
136
144
  }
137
145
  catch (error) {
138
- const message = error instanceof Error ? error.message : 'Error desconocido';
139
- logger_1.logger.error(message);
146
+ const message = error instanceof Error ? error.message : 'Unknown error';
147
+ logger.error(message);
140
148
  process.exit(1);
141
149
  }
142
150
  });
143
- exports.filesCommand = filesGroup;
151
+ export const filesCommand = filesGroup;