plazbot-cli 0.2.26 → 0.3.2

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 +86 -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 +22 -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 +93 -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,27 +1,39 @@
1
1
  import { Command } from 'commander';
2
- import { getStoredCredentials } from '../../utils/credentials';
3
- import { createApiClient } from '../../utils/api';
4
- import { logger } from '../../utils/logger';
5
- import { createSpinner, createTable, theme, formatDate } from '../../utils/ui';
6
- import { WorkerSecretItem } from '../../types/workers';
2
+ import { getStoredCredentials } from '../../utils/credentials.js';
3
+ import { createApiClient } from '../../utils/api.js';
4
+ import { logger } from '../../utils/logger.js';
5
+ import { addExamples } from '../../utils/help.js';
6
+ import { createSpinner, createTable, theme, formatDate } from '../../utils/ui.js';
7
+ import { WorkerSecretItem } from '../../types/workers.js';
7
8
  import readline from 'readline';
8
9
 
9
10
  // ── Comando padre: secret ───────────────────────────────────────────────────
10
11
 
11
12
  export const secretCommand = new Command('secret')
12
- .description('Gestionar secrets (variables de entorno) de los workers')
13
+ .description('Manage worker secrets (environment variables)')
13
14
  .addCommand(secretSetCommand())
14
15
  .addCommand(secretListCommand())
15
16
  .addCommand(secretRemoveCommand());
16
17
 
18
+ addExamples(secretCommand, [
19
+ { description: 'Save (or update) an API key as a secret',
20
+ command: 'plazbot workers secret set STRIPE_API_KEY sk_live_xxxxx' },
21
+ { description: 'List every secret (values are hidden)',
22
+ command: 'plazbot workers secret list' },
23
+ { description: 'Delete a secret with confirmation prompt',
24
+ command: 'plazbot workers secret remove STRIPE_API_KEY' },
25
+ { description: 'Delete a secret without confirmation',
26
+ command: 'plazbot workers secret remove STRIPE_API_KEY -f' },
27
+ ]);
28
+
17
29
  // ── secret set ──────────────────────────────────────────────────────────────
18
30
 
19
31
  function secretSetCommand(): Command {
20
32
  return new Command('set')
21
- .description('Crear o actualizar un secret')
22
- .argument('<key>', 'Nombre del secret (ej: STRIPE_API_KEY)')
23
- .argument('<value>', 'Valor del secret')
24
- .option('--dev', 'Usar ambiente de desarrollo', false)
33
+ .description('Create or update a secret')
34
+ .argument('<key>', 'Secret name (e.g.: STRIPE_API_KEY)')
35
+ .argument('<value>', 'Secret value')
36
+ .option('--dev', 'Use development environment', false)
25
37
  .action(async (key: string, value: string, options: { dev?: boolean }) => {
26
38
  try {
27
39
  const credentials = await getStoredCredentials();
@@ -32,21 +44,21 @@ function secretSetCommand(): Command {
32
44
  dev: options.dev,
33
45
  });
34
46
 
35
- const spinner = createSpinner(`Guardando secret "${key}"...`);
47
+ const spinner = createSpinner(`Saving secret "${key}"...`);
36
48
  spinner.start();
37
49
 
38
50
  await api.put('/api/worker/secrets', { key, value });
39
51
 
40
- spinner.succeed(`Secret "${key}" guardado`);
41
- logger.dim(` Disponible en tus workers como plz.env.${key}`);
52
+ spinner.succeed(`Secret "${key}" saved`);
53
+ logger.dim(` Available in your workers as plz.env.${key}`);
42
54
  console.log();
43
55
 
44
56
  if (options.dev) {
45
- logger.warning('Ambiente: desarrollo');
57
+ logger.warning('Environment: development');
46
58
  }
47
59
 
48
60
  } catch (error) {
49
- const message = error instanceof Error ? error.message : 'Error desconocido';
61
+ const message = error instanceof Error ? error.message : 'Unknown error';
50
62
  logger.error(message);
51
63
  process.exit(1);
52
64
  }
@@ -57,8 +69,8 @@ function secretSetCommand(): Command {
57
69
 
58
70
  function secretListCommand(): Command {
59
71
  return new Command('list')
60
- .description('Lista todos los secrets del workspace (sin mostrar valores)')
61
- .option('--dev', 'Usar ambiente de desarrollo', false)
72
+ .description('List all secrets in the workspace (without showing values)')
73
+ .option('--dev', 'Use development environment', false)
62
74
  .action(async (options: { dev?: boolean }) => {
63
75
  try {
64
76
  const credentials = await getStoredCredentials();
@@ -69,7 +81,7 @@ function secretListCommand(): Command {
69
81
  dev: options.dev,
70
82
  });
71
83
 
72
- const spinner = createSpinner('Obteniendo secrets...');
84
+ const spinner = createSpinner('Fetching secrets...');
73
85
  spinner.start();
74
86
 
75
87
  const response = await api.get('/api/worker/secrets');
@@ -78,8 +90,8 @@ function secretListCommand(): Command {
78
90
  spinner.stop();
79
91
 
80
92
  if (!secrets || secrets.length === 0) {
81
- logger.info('\n No hay secrets configurados');
82
- logger.dim(' Agrega uno: plazbot workers secret set MI_KEY mi_valor');
93
+ logger.info('\n No secrets configured');
94
+ logger.dim(' Add one: plazbot workers secret set MY_KEY my_value');
83
95
  console.log();
84
96
  return;
85
97
  }
@@ -93,18 +105,18 @@ function secretListCommand(): Command {
93
105
  ]);
94
106
 
95
107
  console.log(createTable(
96
- ['Key', 'Valor', 'Actualizado'],
108
+ ['Key', 'Value', 'Updated'],
97
109
  rows,
98
110
  ));
99
111
 
100
112
  console.log();
101
113
 
102
114
  if (options.dev) {
103
- logger.warning('Ambiente: desarrollo');
115
+ logger.warning('Environment: development');
104
116
  }
105
117
 
106
118
  } catch (error) {
107
- const message = error instanceof Error ? error.message : 'Error desconocido';
119
+ const message = error instanceof Error ? error.message : 'Unknown error';
108
120
  logger.error(message);
109
121
  process.exit(1);
110
122
  }
@@ -115,10 +127,10 @@ function secretListCommand(): Command {
115
127
 
116
128
  function secretRemoveCommand(): Command {
117
129
  return new Command('remove')
118
- .description('Elimina un secret del workspace')
119
- .argument('<key>', 'Nombre del secret a eliminar')
120
- .option('-f, --force', 'Eliminar sin confirmacion', false)
121
- .option('--dev', 'Usar ambiente de desarrollo', false)
130
+ .description('Delete a secret from the workspace')
131
+ .argument('<key>', 'Name of the secret to delete')
132
+ .option('-f, --force', 'Delete without confirmation', false)
133
+ .option('--dev', 'Use development environment', false)
122
134
  .action(async (key: string, options: { dev?: boolean; force?: boolean }) => {
123
135
  try {
124
136
  const credentials = await getStoredCredentials();
@@ -131,32 +143,32 @@ function secretRemoveCommand(): Command {
131
143
 
132
144
  if (!options.force) {
133
145
  const confirmed = await askConfirmation(
134
- ` Eliminar secret "${key}"? (y/N): `
146
+ ` Delete secret "${key}"? (y/N): `
135
147
  );
136
148
 
137
149
  if (!confirmed) {
138
- logger.info('\n Operacion cancelada');
150
+ logger.info('\n Operation cancelled');
139
151
  process.exit(0);
140
152
  }
141
153
  }
142
154
 
143
- const spinner = createSpinner(`Eliminando secret "${key}"...`);
155
+ const spinner = createSpinner(`Deleting secret "${key}"...`);
144
156
  spinner.start();
145
157
 
146
158
  await api.delete(`/api/worker/secrets/${encodeURIComponent(key)}`);
147
159
 
148
- spinner.succeed(`Secret "${key}" eliminado`);
160
+ spinner.succeed(`Secret "${key}" deleted`);
149
161
  console.log();
150
162
 
151
163
  if (options.dev) {
152
- logger.warning('Ambiente: desarrollo');
164
+ logger.warning('Environment: development');
153
165
  }
154
166
 
155
167
  } catch (error: any) {
156
168
  if (error.response?.status === 404) {
157
- logger.error(`Secret "${key}" no encontrado`);
169
+ logger.error(`Secret "${key}" not found`);
158
170
  } else {
159
- const message = error instanceof Error ? error.message : 'Error desconocido';
171
+ const message = error instanceof Error ? error.message : 'Unknown error';
160
172
  logger.error(message);
161
173
  }
162
174
  process.exit(1);
@@ -1,8 +1,9 @@
1
1
  import { Command } from 'commander';
2
- import { getStoredCredentials } from '../../utils/credentials';
3
- import { createApiClient } from '../../utils/api';
4
- import { logger } from '../../utils/logger';
5
- import { createSpinner, theme } from '../../utils/ui';
2
+ import { getStoredCredentials } from '../../utils/credentials.js';
3
+ import { createApiClient } from '../../utils/api.js';
4
+ import { logger } from '../../utils/logger.js';
5
+ import { addExamples } from '../../utils/help.js';
6
+ import { createSpinner, theme } from '../../utils/ui.js';
6
7
 
7
8
  interface WorkerTestResult {
8
9
  success: boolean;
@@ -12,13 +13,13 @@ interface WorkerTestResult {
12
13
  }
13
14
 
14
15
  export const testCommand = new Command('test')
15
- .description('Ejecutar un worker manualmente para probarlo')
16
- .argument('<name>', 'Nombre del worker a ejecutar')
17
- .option('-p, --payload <json>', 'Payload JSON para el worker (ej: \'{"producto":"iPhone"}\')')
18
- .option('-t, --type <type>', 'Tipo del worker (tool, worker, sync, schedule, webhook)')
19
- .option('--contact <id>', 'ID del contacto (contexto para tools)')
20
- .option('--agent <id>', 'ID del agente (contexto para tools)')
21
- .option('--dev', 'Usar ambiente de desarrollo', false)
16
+ .description('Run a worker manually to test it')
17
+ .argument('<name>', 'Name of the worker to run')
18
+ .option('-p, --payload <json>', 'JSON payload for the worker (e.g.: \'{"product":"iPhone"}\')')
19
+ .option('-t, --type <type>', 'Worker type (tool, worker, sync, schedule, webhook)')
20
+ .option('--contact <id>', 'Contact ID (context for tools)')
21
+ .option('--agent <id>', 'Agent ID (context for tools)')
22
+ .option('--dev', 'Use development environment', false)
22
23
  .action(async (name: string, options: {
23
24
  payload?: string;
24
25
  type?: string;
@@ -41,13 +42,13 @@ export const testCommand = new Command('test')
41
42
  try {
42
43
  payload = JSON.parse(options.payload);
43
44
  } catch {
44
- logger.error('El payload no es JSON valido');
45
- logger.dim('Ejemplo: --payload \'{"producto":"iPhone 15"}\'');
45
+ logger.error('Payload is not valid JSON');
46
+ logger.dim('Example: --payload \'{"product":"iPhone 15"}\'');
46
47
  process.exit(1);
47
48
  }
48
49
  }
49
50
 
50
- logger.title(`Ejecutando worker "${name}"`);
51
+ logger.title(`Running worker "${name}"`);
51
52
  console.log();
52
53
 
53
54
  if (Object.keys(payload).length > 0) {
@@ -55,7 +56,7 @@ export const testCommand = new Command('test')
55
56
  console.log();
56
57
  }
57
58
 
58
- const spinner = createSpinner('Ejecutando...');
59
+ const spinner = createSpinner('Running...');
59
60
  spinner.start();
60
61
 
61
62
  const response = await api.post('/api/worker/execute', {
@@ -73,16 +74,16 @@ export const testCommand = new Command('test')
73
74
  spinner.stop();
74
75
 
75
76
  if (data.success) {
76
- logger.success(`Ejecutado en ${duration}ms`);
77
+ logger.success(`Completed in ${duration}ms`);
77
78
  } else {
78
- logger.error(`Fallo en ${duration}ms`);
79
+ logger.error(`Failed in ${duration}ms`);
79
80
  }
80
81
 
81
82
  console.log();
82
83
 
83
84
  // Mostrar resultado
84
85
  if (data.result !== undefined && data.result !== null) {
85
- logger.label('Resultado', '');
86
+ logger.label('Result', '');
86
87
 
87
88
  const result = data.result as Record<string, unknown>;
88
89
 
@@ -117,17 +118,28 @@ export const testCommand = new Command('test')
117
118
  console.log();
118
119
 
119
120
  if (options.dev) {
120
- logger.warning('Ambiente: desarrollo');
121
+ logger.warning('Environment: development');
121
122
  }
122
123
 
123
124
  } catch (error: any) {
124
125
  if (error.response?.status === 404) {
125
- logger.error(`Worker "${name}" no encontrado o inactivo`);
126
- logger.dim('Verifica que el worker este desplegado con: plazbot workers list');
126
+ logger.error(`Worker "${name}" not found or inactive`);
127
+ logger.dim('Verify the worker is deployed with: plazbot workers list');
127
128
  } else {
128
- const message = error.response?.data?.message || error.message || 'Error desconocido';
129
+ const message = error.response?.data?.message || error.message || 'Unknown error';
129
130
  logger.error(message);
130
131
  }
131
132
  process.exit(1);
132
133
  }
133
134
  });
135
+
136
+ addExamples(testCommand, [
137
+ { description: 'Run a worker without payload',
138
+ command: 'plazbot workers test my-tool' },
139
+ { description: 'Run a worker with a JSON payload',
140
+ command: 'plazbot workers test get-stock -p \'{"product":"iPhone 15"}\'' },
141
+ { description: 'Run a tool with contact and agent context',
142
+ command: 'plazbot workers test my-tool --contact ctc_AbcDef123 --agent agt_AbcDef123' },
143
+ { description: 'Run against the local backend',
144
+ command: 'plazbot workers test my-tool --dev' },
145
+ ]);