plazbot-cli 0.4.0 → 0.5.0

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 (76) hide show
  1. package/README.md +67 -111
  2. package/dist/cli.js +26 -11
  3. package/dist/commands/agent/ai-config.js +264 -63
  4. package/dist/commands/agent/chat.js +16 -11
  5. package/dist/commands/agent/copy.js +49 -13
  6. package/dist/commands/agent/create.js +62 -17
  7. package/dist/commands/agent/delete.js +50 -39
  8. package/dist/commands/agent/enable-widget.js +47 -27
  9. package/dist/commands/agent/export.js +179 -88
  10. package/dist/commands/agent/files.js +155 -73
  11. package/dist/commands/agent/get.js +24 -16
  12. package/dist/commands/agent/index.js +12 -10
  13. package/dist/commands/agent/list.js +20 -11
  14. package/dist/commands/agent/monitor.js +101 -53
  15. package/dist/commands/agent/on-message.js +55 -32
  16. package/dist/commands/agent/set.js +230 -82
  17. package/dist/commands/agent/templates.js +259 -156
  18. package/dist/commands/agent/tools.js +356 -123
  19. package/dist/commands/agent/update.js +69 -28
  20. package/dist/commands/agent/validate.js +72 -40
  21. package/dist/commands/agent/wizard.js +240 -329
  22. package/dist/commands/auth/browser-login.js +37 -31
  23. package/dist/commands/auth/login.js +49 -45
  24. package/dist/commands/auth/logout.js +20 -11
  25. package/dist/commands/auth/status.js +36 -12
  26. package/dist/commands/auth/workspace.js +61 -27
  27. package/dist/commands/portal/add-agent.js +106 -45
  28. package/dist/commands/portal/add-link.js +25 -28
  29. package/dist/commands/portal/clear-links.js +39 -19
  30. package/dist/commands/portal/create.js +66 -37
  31. package/dist/commands/portal/delete.js +40 -45
  32. package/dist/commands/portal/get.js +21 -54
  33. package/dist/commands/portal/index.js +12 -12
  34. package/dist/commands/portal/list.js +34 -52
  35. package/dist/commands/portal/shared.js +92 -0
  36. package/dist/commands/portal/update.js +100 -70
  37. package/dist/commands/whatsapp/broadcast.js +169 -77
  38. package/dist/commands/whatsapp/channels.js +167 -65
  39. package/dist/commands/whatsapp/chat.js +45 -46
  40. package/dist/commands/whatsapp/connect-flow.js +16 -15
  41. package/dist/commands/whatsapp/connect.js +36 -21
  42. package/dist/commands/whatsapp/delete-webhook.js +42 -25
  43. package/dist/commands/whatsapp/index.js +15 -16
  44. package/dist/commands/whatsapp/register-webhook.js +43 -26
  45. package/dist/commands/whatsapp/send-template.js +62 -61
  46. package/dist/commands/whatsapp/send.js +46 -33
  47. package/dist/commands/whatsapp/setup.js +62 -52
  48. package/dist/commands/whatsapp/shared.js +75 -0
  49. package/dist/commands/whatsapp/widget.js +82 -45
  50. package/dist/commands/workers/deploy.js +80 -58
  51. package/dist/commands/workers/index.js +8 -8
  52. package/dist/commands/workers/list.js +42 -20
  53. package/dist/commands/workers/logs.js +139 -36
  54. package/dist/commands/workers/remove.js +45 -47
  55. package/dist/commands/workers/secret.js +159 -83
  56. package/dist/commands/workers/test.js +108 -60
  57. package/dist/schemas/agent.config.schema.json +183 -8
  58. package/dist/studio/api/sseClient.js +1 -1
  59. package/dist/studio/api/studioApi.js +8 -0
  60. package/dist/studio/components/App.js +12 -0
  61. package/dist/studio/components/Footer.js +1 -1
  62. package/dist/studio/index.js +77 -14
  63. package/dist/studio/runOneShot.js +62 -23
  64. package/dist/studio/runRepl.js +5 -5
  65. package/dist/studio/slash/handlers.js +11 -8
  66. package/dist/studio/state/store.js +1 -1
  67. package/dist/utils/agent-errors.js +14 -11
  68. package/dist/utils/agent-patch.js +60 -0
  69. package/dist/utils/banner.js +9 -5
  70. package/dist/utils/confirm.js +31 -0
  71. package/dist/utils/credentials.js +13 -3
  72. package/dist/utils/logger.js +13 -10
  73. package/dist/utils/output.js +78 -0
  74. package/dist/utils/phone.js +22 -0
  75. package/dist/utils/ui.js +14 -11
  76. package/package.json +2 -2
package/README.md CHANGED
@@ -1,159 +1,115 @@
1
1
  # Plazbot CLI
2
2
 
3
- CLI oficial de Plazbot: conecta WhatsApp, envía mensajes, gestiona agentes IA y despliega workers desde tu terminal.
4
-
5
- ## Empieza en 3 comandos
3
+ The official Plazbot CLI: connect WhatsApp, send messages, manage AI agents and deploy workers from your terminal.
6
4
 
7
5
  ```bash
8
6
  npm i -g plazbot-cli
9
- plazbot login # abre el navegador y autorizas (sin copiar API key)
10
- plazbot whatsapp setup # conecta tu número y prueba tu primer mensaje
7
+ plazbot login # sign in from the browser (no API key to copy)
8
+ plazbot whatsapp setup # connect a number and send your first message
11
9
  ```
12
10
 
13
- `plazbot whatsapp setup` te guía paso a paso: conecta un número (WhatsApp API o tu
14
- WhatsApp Business actual), te pide escribir "hola" desde tu celular, responde por la API
15
- y registra tu webhook. Al final te da el código para tu app.
11
+ Requires Node.js 18.17 or later. Full documentation: https://developers.plazbot.com/cli
16
12
 
17
- ### Sesión
13
+ ## Session
18
14
 
19
15
  ```bash
20
- plazbot login [--zone LA|EU] [--no-browser] # login por navegador
21
- plazbot whoami # sesión activa
22
- plazbot workspace list | use <id> # cambiar de workspace
23
- plazbot logout
16
+ plazbot login [--zone LA|EU] [--no-browser] # browser sign-in
17
+ plazbot whoami # active account, workspace and zone
18
+ plazbot workspace list # your workspaces (● = active)
19
+ plazbot workspace use wok_AbcDef123 # switch workspace
20
+ plazbot logout # remove the local session
24
21
  ```
25
22
 
26
- En CI o servidores usa variables de entorno en lugar de `plazbot login`:
27
- `PLAZBOT_API_KEY`, `PLAZBOT_WORKSPACE_ID` y `PLAZBOT_ZONE` (`LA` o `EU`).
28
-
29
- ### WhatsApp
23
+ In CI or on servers, use environment variables instead of `plazbot login`:
30
24
 
31
25
  ```bash
32
- plazbot whatsapp setup # asistente de primer uso
33
- plazbot whatsapp connect [--business] # conectar un número
34
- plazbot whatsapp send-message --to 51912345678 --message "Hola"
35
- plazbot whatsapp send-template --phone 51912345678 --template welcome --var 1=Ana
36
- plazbot whatsapp register-webhook --number 51966446311 --url https://tu-app.com/whatsapp
26
+ export PLAZBOT_API_KEY=...
27
+ export PLAZBOT_WORKSPACE_ID=wok_...
28
+ export PLAZBOT_ZONE=LA # or EU
37
29
  ```
38
30
 
39
- Documentación: https://developers.plazbot.com/cli
31
+ ## WhatsApp
40
32
 
41
- ## Más funciones
33
+ Phone numbers always go in `-p, --phone`, in any international format (`+51912345678`, `"+51 912 345 678"`, `0051912345678`).
42
34
 
43
- 🧠 **Agent Studio (REPL interactivo, estilo Claude Code)**
44
35
  ```bash
45
- # Modo REPL completo (TUI con Ink)
46
- plazbot studio
47
-
48
- # One-shot (resultado a stdout, sin TUI)
49
- plazbot studio ask "lista mis agentes"
50
- plazbot studio -m "crea un agente de ventas para WhatsApp"
51
-
52
- # NDJSON crudo de los chunks SSE
53
- plazbot studio ask "diagnostica el agente xyz" --json
54
-
55
- # Backend local
56
- plazbot studio --dev
36
+ plazbot whatsapp connect [--business]
37
+ plazbot whatsapp send-message -p +51912345678 -m "Hello"
38
+ plazbot whatsapp send-template -p +51912345678 -t welcome --var name=Anna
39
+ plazbot whatsapp broadcast -t welcome --phones ./numbers.txt --dry-run
40
+ plazbot whatsapp chat -p +51912345678
41
+ plazbot whatsapp assign -p +51912345678 -a age_AbcDef123
42
+ plazbot whatsapp channels
43
+ plazbot whatsapp register-webhook -p +51912345678 -u https://your-app.com/whatsapp
57
44
  ```
58
45
 
59
- Slash commands: `/help`, `/clear`, `/quit`, `/agents`, `/load <id>`, `/save`,
60
- `/diagnose`, `/panel`, `/json`, `/preview`.
46
+ ## AI agents
61
47
 
62
- Atajos: `Tab` panel · `Esc` cancelar stream · `Ctrl+C` salir.
63
-
64
- 🤖 **Agent Management**
65
48
  ```bash
66
- # Create a new agent
67
- plazbot agent create -n "My Agent" -d "Description"
68
-
69
- # List all agents
70
49
  plazbot agent list
71
-
72
- # Delete an agent
73
- plazbot agent delete -i agent_id
50
+ plazbot agent create # interactive wizard
51
+ plazbot agent create ./agent.json # from a JSON file
52
+ plazbot agent templates --list # ready-made templates
53
+ plazbot agent get age_AbcDef123
54
+ plazbot agent chat age_AbcDef123
55
+ plazbot agent message age_AbcDef123 -q "What are your opening hours?"
56
+ plazbot agent export age_AbcDef123 -o agent.json
57
+ plazbot agent validate agent.json --strict
58
+ plazbot agent update age_AbcDef123 ./changes.json # only the fields in the file change
59
+ plazbot agent ai-config age_AbcDef123 --provider openai --model gpt-4o --api-token sk-...
60
+ plazbot agent monitor age_AbcDef123
61
+ plazbot agent delete age_AbcDef123
74
62
  ```
75
63
 
76
- 🌐 **Portal Management**
77
- ```bash
78
- # Add a link to portal
79
- plazbot portal add-link -n "Example" -u "https://example.com"
64
+ ## Studio
80
65
 
81
- # Clear all links
82
- plazbot portal clear-links
83
- ```
66
+ An interactive terminal assistant to create, diagnose and edit agents in natural language.
84
67
 
85
- 💬 **WhatsApp Integration**
86
68
  ```bash
87
- # Send a message
88
- plazbot whatsapp send-message -t "+1234567890" -m "Hello"
89
-
90
- # Send a template
91
- plazbot whatsapp send-template -t "+1234567890" -n "welcome"
92
-
93
- # Manage webhooks
94
- plazbot whatsapp register-webhook -u "https://your-webhook.com"
95
- plazbot whatsapp delete-webhook
69
+ plazbot studio
70
+ plazbot studio ask "list my agents"
71
+ plazbot studio ask "diagnose agent age_AbcDef123" --json # NDJSON stream
96
72
  ```
97
73
 
98
- ## Installation
74
+ ## Portals
99
75
 
100
76
  ```bash
101
- npm install -g plazbot-cli
77
+ plazbot portal list
78
+ plazbot portal create -n "Help Center" -t "How can we help?"
79
+ plazbot portal add-agent por_AbcDef123 -a age_AbcDef123
80
+ plazbot portal add-link por_AbcDef123 -t "Docs" -u https://docs.example.com
81
+ plazbot portal update por_AbcDef123 --disable
102
82
  ```
103
83
 
104
- ## Usage
105
-
106
- ### Portal Commands
84
+ ## Workers
107
85
 
108
86
  ```bash
109
- # Add a link to portal
110
- plazbot portal add-link -n "Example Link" -u "https://example.com"
111
-
112
- # Clear all links
113
- plazbot portal clear-links
87
+ plazbot workers deploy # every file in ./workers
88
+ plazbot workers list
89
+ plazbot workers test my-tool -d '{"product":"iPhone 15"}'
90
+ plazbot workers logs my-tool --follow
91
+ echo "$STRIPE_KEY" | plazbot workers secret set STRIPE_API_KEY
114
92
  ```
115
93
 
116
- ### WhatsApp Commands
117
-
118
- ```bash
119
- # Send a direct message
120
- plazbot whatsapp send-message -t "+1234567890" -m "Hello World"
94
+ ## Scripting
121
95
 
122
- # Send a template message
123
- plazbot whatsapp send-template -t "+1234567890" -n "welcome_template"
96
+ Every command is built to run in scripts and CI:
124
97
 
125
- # Register a webhook
126
- plazbot whatsapp register-webhook -u "https://your-webhook.com"
98
+ - **`--json`**: commands that read, list or change data print JSON to stdout. Progress messages go to stderr. Errors print as `{"error": {"message", "code", "hint"}}` on stderr.
99
+ - **`-y, --yes`**: skips confirmation prompts (`--confirm` also works). Without a terminal, destructive commands refuse to run unless you pass `--yes`, so they never hang waiting for input.
100
+ - **Exit codes**: `0` means success. `1` means something failed, including partial failures such as a broadcast with failed sends or a deploy with failed files.
127
101
 
128
- # Delete a webhook
129
- plazbot whatsapp delete-webhook
102
+ ```bash
103
+ plazbot agent list --json | jq -r '.[].id'
104
+ plazbot agent delete age_AbcDef123 --yes --json
130
105
  ```
131
106
 
132
- ## Command Options
133
-
134
- ### Portal Commands
135
- - `add-link`
136
- - `-n, --name`: Link name
137
- - `-u, --url`: Link URL
138
- - `clear-links`: No options required
139
-
140
- ### WhatsApp Commands
141
- - `send-message`
142
- - `-t, --to`: Recipient phone number
143
- - `-m, --message`: Message text
144
- - `send-template`
145
- - `-t, --to`: Recipient phone number
146
- - `-n, --name`: Template name
147
- - `register-webhook`
148
- - `-u, --url`: Webhook URL
149
- - `delete-webhook`: No options required
107
+ Run `plazbot <command> --help` for every option and more examples.
150
108
 
151
- ## Requirements
109
+ ## Support
152
110
 
153
- - Node.js 14 or higher
154
- - npm or yarn package manager
155
- - Valid Plazbot API credentials
111
+ Documentation: https://developers.plazbot.com/cli · support@plazbot.com
156
112
 
157
- ## Support
113
+ ## License
158
114
 
159
- For more documentation, please visit our [Documentation](https://docs.plazbot.com) or contact support@plazbot.com
115
+ MIT
package/dist/cli.js CHANGED
@@ -10,34 +10,49 @@ import { whatsappCommands } from './commands/whatsapp/index.js';
10
10
  import { workersCommands } from './commands/workers/index.js';
11
11
  import { studioCommand } from './studio/index.js';
12
12
  import { showBanner } from './utils/banner.js';
13
- // Guard de runtime: Plazbot CLI v0.3+ requiere Node 18.17+
13
+ import { fail, setJsonMode } from './utils/output.js';
14
+ // Runtime guard: Plazbot CLI requires Node 18.17+
14
15
  const [major, minor] = process.versions.node.split('.').map(Number);
15
16
  if (major < 18 || (major === 18 && minor < 17)) {
16
- console.error(`Plazbot CLI v0.3+ requires Node.js >=18.17.0. Current version: ${process.versions.node}`);
17
+ console.error(`Plazbot CLI requires Node.js >=18.17.0. Current version: ${process.versions.node}`);
17
18
  process.exit(1);
18
19
  }
19
- // Leer version desde package.json
20
+ // Read the version from package.json
20
21
  const __dirname = dirname(fileURLToPath(import.meta.url));
21
22
  const pkgPath = join(__dirname, '..', 'package.json');
22
23
  const { version } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
23
- // Configuracion basica del CLI
24
+ // Basic CLI configuration
24
25
  program
25
26
  .name('plazbot')
26
27
  .description('Official Plazbot CLI - AI agents for WhatsApp, portals and developers')
27
28
  .version(version);
28
- // Registrar todos los comandos de autenticacion
29
+ // Register commands
29
30
  authCommands.forEach(cmd => program.addCommand(cmd));
30
- // Registrar todos los comandos de agente
31
31
  program.addCommand(agentCommands);
32
- // Registrar todos los comandos de portal
33
32
  program.addCommand(portalCommands);
34
- // Registrar todos los comandos de WhatsApp
35
33
  program.addCommand(whatsappCommands);
36
- // Registrar todos los comandos de Workers
37
34
  program.addCommand(workersCommands);
38
- // Registrar el comando Studio (REPL interactivo)
39
35
  program.addCommand(studioCommand);
40
- // Si no se pasan argumentos, mostrar banner
36
+ // Settings shared by every command:
37
+ // - --dev (local backend) is an internal flag: it keeps working but is hidden from help.
38
+ // - Usage errors suggest --help and the closest command/option.
39
+ function configureTree(cmd) {
40
+ cmd.showHelpAfterError('(run with --help for usage)');
41
+ cmd.showSuggestionAfterError(true);
42
+ for (const opt of cmd.options) {
43
+ if (opt.long === '--dev')
44
+ opt.hideHelp();
45
+ }
46
+ cmd.commands.forEach(configureTree);
47
+ }
48
+ configureTree(program);
49
+ // --json on the command being run: stdout only carries JSON
50
+ program.hook('preAction', (_thisCommand, actionCommand) => {
51
+ setJsonMode(Boolean(actionCommand.opts().json));
52
+ });
53
+ // Anything that escapes a command still ends with a clear message and exit code 1
54
+ process.on('unhandledRejection', (reason) => fail(reason));
55
+ // Without arguments, show the banner
41
56
  if (process.argv.length <= 2) {
42
57
  showBanner().then(() => {
43
58
  program.outputHelp();