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.
- package/CLAUDE.md +34 -5
- package/README.md +21 -0
- package/dist/cli.js +32 -20
- package/dist/commands/agent/ai-config.js +98 -50
- package/dist/commands/agent/chat.js +80 -74
- package/dist/commands/agent/copy.js +23 -21
- package/dist/commands/agent/create.js +42 -72
- package/dist/commands/agent/delete.js +29 -30
- package/dist/commands/agent/enable-widget.js +30 -26
- package/dist/commands/agent/export.js +90 -77
- package/dist/commands/agent/files.js +68 -60
- package/dist/commands/agent/get.js +101 -87
- package/dist/commands/agent/index.js +53 -39
- package/dist/commands/agent/list.js +26 -24
- package/dist/commands/agent/monitor.js +91 -86
- package/dist/commands/agent/on-message.js +40 -37
- package/dist/commands/agent/set.js +62 -59
- package/dist/commands/agent/templates.js +109 -108
- package/dist/commands/agent/tools.js +64 -65
- package/dist/commands/agent/update.js +28 -27
- package/dist/commands/agent/validate.js +127 -0
- package/dist/commands/agent/wizard.js +152 -159
- package/dist/commands/auth/index.js +7 -10
- package/dist/commands/auth/login.js +50 -37
- package/dist/commands/auth/logout.js +16 -14
- package/dist/commands/auth/status.js +19 -16
- package/dist/commands/portal/add-agent.js +26 -24
- package/dist/commands/portal/add-link.js +21 -17
- package/dist/commands/portal/clear-links.js +17 -15
- package/dist/commands/portal/create.js +25 -21
- package/dist/commands/portal/delete.js +31 -30
- package/dist/commands/portal/get.js +33 -31
- package/dist/commands/portal/index.js +30 -22
- package/dist/commands/portal/list.js +34 -30
- package/dist/commands/portal/update.js +41 -33
- package/dist/commands/whatsapp/broadcast.js +40 -37
- package/dist/commands/whatsapp/channels.js +40 -34
- package/dist/commands/whatsapp/chat.js +33 -32
- package/dist/commands/whatsapp/connect.js +53 -52
- package/dist/commands/whatsapp/delete-webhook.js +19 -17
- package/dist/commands/whatsapp/index.js +35 -25
- package/dist/commands/whatsapp/register-webhook.js +21 -19
- package/dist/commands/whatsapp/send-template.js +39 -31
- package/dist/commands/whatsapp/send.js +27 -23
- package/dist/commands/whatsapp/widget.js +35 -31
- package/dist/commands/workers/deploy.js +49 -44
- package/dist/commands/workers/index.js +28 -18
- package/dist/commands/workers/list.js +43 -35
- package/dist/commands/workers/logs.js +38 -32
- package/dist/commands/workers/remove.js +38 -37
- package/dist/commands/workers/secret.js +63 -58
- package/dist/commands/workers/test.js +44 -36
- package/dist/schemas/agent.config.schema.json +569 -0
- package/dist/studio/api/sseClient.js +97 -0
- package/dist/studio/api/studioApi.js +25 -0
- package/dist/studio/api/types.js +16 -0
- package/dist/studio/components/AgentPanel.js +35 -0
- package/dist/studio/components/App.js +214 -0
- package/dist/studio/components/ChatLog.js +59 -0
- package/dist/studio/components/Footer.js +11 -0
- package/dist/studio/components/Header.js +8 -0
- package/dist/studio/components/Input.js +15 -0
- package/dist/studio/components/Message.js +56 -0
- package/dist/studio/components/Suggestions.js +11 -0
- package/dist/studio/components/ToolCall.js +33 -0
- package/dist/studio/components/WhatsappConnectCard.js +57 -0
- package/dist/studio/index.js +42 -0
- package/dist/studio/render/json.js +16 -0
- package/dist/studio/render/markdown.js +86 -0
- package/dist/studio/render/steps.js +58 -0
- package/dist/studio/runOneShot.js +96 -0
- package/dist/studio/runRepl.js +52 -0
- package/dist/studio/slash/handlers.js +199 -0
- package/dist/studio/slash/parser.js +46 -0
- package/dist/studio/slash/registry.js +16 -0
- package/dist/studio/state/store.js +181 -0
- package/dist/studio/whatsapp/api.js +63 -0
- package/dist/studio/whatsapp/polling.js +77 -0
- package/dist/studio/whatsapp/types.js +31 -0
- package/dist/types/agent.js +1 -2
- package/dist/types/auth.js +1 -2
- package/dist/types/common.js +1 -2
- package/dist/types/message.js +1 -2
- package/dist/types/portal.js +1 -2
- package/dist/types/workers.js +1 -2
- package/dist/utils/agent-errors.js +46 -0
- package/dist/utils/api.js +8 -9
- package/dist/utils/banner.js +33 -34
- package/dist/utils/credentials.js +12 -20
- package/dist/utils/help.js +44 -0
- package/dist/utils/logger.js +13 -19
- package/dist/utils/ui.js +35 -49
- package/package.json +22 -10
- package/src/cli.ts +24 -8
- package/src/commands/agent/ai-config.ts +89 -34
- package/src/commands/agent/chat.ts +49 -37
- package/src/commands/agent/copy.ts +19 -13
- package/src/commands/agent/create.ts +32 -22
- package/src/commands/agent/delete.ts +24 -18
- package/src/commands/agent/enable-widget.ts +31 -23
- package/src/commands/agent/export.ts +72 -51
- package/src/commands/agent/files.ts +51 -39
- package/src/commands/agent/get.ts +86 -66
- package/src/commands/agent/index.ts +36 -18
- package/src/commands/agent/list.ts +22 -16
- package/src/commands/agent/monitor.ts +67 -56
- package/src/commands/agent/on-message.ts +36 -27
- package/src/commands/agent/set.ts +47 -37
- package/src/commands/agent/templates.ts +90 -82
- package/src/commands/agent/tools.ts +53 -47
- package/src/commands/agent/update.ts +28 -20
- package/src/commands/agent/validate.ts +135 -0
- package/src/commands/agent/wizard.ts +114 -114
- package/src/commands/auth/index.ts +3 -3
- package/src/commands/auth/login.ts +44 -29
- package/src/commands/auth/logout.ts +16 -10
- package/src/commands/auth/status.ts +14 -8
- package/src/commands/portal/add-agent.ts +23 -17
- package/src/commands/portal/add-link.ts +17 -9
- package/src/commands/portal/clear-links.ts +13 -7
- package/src/commands/portal/create.ts +20 -12
- package/src/commands/portal/delete.ts +28 -20
- package/src/commands/portal/get.ts +25 -19
- package/src/commands/portal/index.ts +22 -10
- package/src/commands/portal/list.ts +27 -19
- package/src/commands/portal/update.ts +38 -26
- package/src/commands/whatsapp/broadcast.ts +28 -18
- package/src/commands/whatsapp/channels.ts +31 -20
- package/src/commands/whatsapp/chat.ts +20 -12
- package/src/commands/whatsapp/connect.ts +39 -31
- package/src/commands/whatsapp/delete-webhook.ts +15 -9
- package/src/commands/whatsapp/index.ts +24 -10
- package/src/commands/whatsapp/register-webhook.ts +16 -10
- package/src/commands/whatsapp/send-template.ts +33 -21
- package/src/commands/whatsapp/send.ts +23 -15
- package/src/commands/whatsapp/widget.ts +25 -17
- package/src/commands/workers/deploy.ts +34 -22
- package/src/commands/workers/index.ts +21 -7
- package/src/commands/workers/list.ts +31 -19
- package/src/commands/workers/logs.ts +30 -20
- package/src/commands/workers/remove.ts +30 -22
- package/src/commands/workers/secret.ts +46 -34
- package/src/commands/workers/test.ts +34 -22
- package/src/schemas/agent.config.schema.json +569 -0
- package/src/studio/api/sseClient.ts +91 -0
- package/src/studio/api/studioApi.ts +27 -0
- package/src/studio/api/types.ts +96 -0
- package/src/studio/components/App.tsx +266 -0
- package/src/studio/components/ChatLog.tsx +95 -0
- package/src/studio/components/Footer.tsx +38 -0
- package/src/studio/components/Header.tsx +39 -0
- package/src/studio/components/Input.tsx +32 -0
- package/src/studio/components/Message.tsx +87 -0
- package/src/studio/components/Suggestions.tsx +26 -0
- package/src/studio/components/ToolCall.tsx +58 -0
- package/src/studio/components/WhatsappConnectCard.tsx +139 -0
- package/src/studio/index.ts +58 -0
- package/src/studio/render/markdown.ts +93 -0
- package/src/studio/render/steps.ts +57 -0
- package/src/studio/runOneShot.ts +114 -0
- package/src/studio/runRepl.tsx +76 -0
- package/src/studio/slash/handlers.ts +226 -0
- package/src/studio/slash/parser.ts +41 -0
- package/src/studio/slash/registry.ts +54 -0
- package/src/studio/state/store.ts +273 -0
- package/src/studio/whatsapp/api.ts +96 -0
- package/src/studio/whatsapp/polling.ts +93 -0
- package/src/studio/whatsapp/types.ts +80 -0
- package/src/types/agent.ts +1 -1
- package/src/types/auth.ts +4 -3
- package/src/types/portal.ts +1 -1
- package/src/types/workers.ts +1 -1
- package/src/utils/agent-errors.ts +67 -0
- package/src/utils/api.ts +6 -0
- package/src/utils/banner.ts +14 -9
- package/src/utils/credentials.ts +6 -5
- package/src/utils/help.ts +51 -0
- package/tsconfig.json +9 -6
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.removeCommand = new commander_1.Command('remove')
|
|
14
|
-
.description('Elimina un worker del workspace')
|
|
15
|
-
.argument('<name>', 'Nombre del worker a eliminar')
|
|
16
|
-
.option('-f, --force', 'Eliminar sin confirmacion', false)
|
|
17
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
1
|
+
import { Command } from 'commander';
|
|
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 } from '../../utils/ui.js';
|
|
7
|
+
import readline from 'readline';
|
|
8
|
+
export const removeCommand = new Command('remove')
|
|
9
|
+
.description('Delete a worker from the workspace')
|
|
10
|
+
.argument('<name>', 'Name of the worker to delete')
|
|
11
|
+
.option('-f, --force', 'Delete without confirmation', false)
|
|
12
|
+
.option('--dev', 'Use development environment', false)
|
|
18
13
|
.action(async (name, options) => {
|
|
19
14
|
try {
|
|
20
|
-
const credentials = await
|
|
21
|
-
const api =
|
|
15
|
+
const credentials = await getStoredCredentials();
|
|
16
|
+
const api = createApiClient({
|
|
22
17
|
apiKey: credentials.apiKey,
|
|
23
18
|
workspace: credentials.workspace,
|
|
24
19
|
zone: credentials.zone,
|
|
25
20
|
dev: options.dev,
|
|
26
21
|
});
|
|
27
22
|
// Verificar que el worker existe
|
|
28
|
-
const spinner =
|
|
23
|
+
const spinner = createSpinner(`Looking up worker "${name}"...`);
|
|
29
24
|
spinner.start();
|
|
30
25
|
let workerInfo;
|
|
31
26
|
try {
|
|
@@ -36,47 +31,53 @@ exports.removeCommand = new commander_1.Command('remove')
|
|
|
36
31
|
catch (error) {
|
|
37
32
|
spinner.stop();
|
|
38
33
|
if (error.response?.status === 404) {
|
|
39
|
-
|
|
34
|
+
logger.error(`Worker "${name}" not found`);
|
|
40
35
|
}
|
|
41
36
|
else {
|
|
42
|
-
|
|
37
|
+
logger.error(error.response?.data?.message || error.message);
|
|
43
38
|
}
|
|
44
39
|
process.exit(1);
|
|
45
40
|
}
|
|
46
41
|
// Mostrar info del worker
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
logger.warning(`\n You are about to delete the following worker:`);
|
|
43
|
+
logger.divider();
|
|
44
|
+
logger.label('Name', workerInfo.name);
|
|
45
|
+
logger.label('Type', workerInfo.type);
|
|
46
|
+
logger.label('Status', workerInfo.status);
|
|
47
|
+
logger.label('Executions', `${workerInfo.executionCount || 0}`);
|
|
48
|
+
logger.divider();
|
|
54
49
|
// Confirmacion
|
|
55
50
|
if (!options.force) {
|
|
56
|
-
const confirmed = await askConfirmation(`
|
|
51
|
+
const confirmed = await askConfirmation(`Delete worker "${name}"? This action cannot be undone (y/N): `);
|
|
57
52
|
if (!confirmed) {
|
|
58
|
-
|
|
53
|
+
logger.info('\n Operation cancelled');
|
|
59
54
|
process.exit(0);
|
|
60
55
|
}
|
|
61
56
|
}
|
|
62
|
-
const deleteSpinner =
|
|
57
|
+
const deleteSpinner = createSpinner(`Deleting "${name}"...`);
|
|
63
58
|
deleteSpinner.start();
|
|
64
59
|
await api.delete(`/api/worker/${encodeURIComponent(name)}`);
|
|
65
|
-
deleteSpinner.succeed(`Worker "${name}"
|
|
60
|
+
deleteSpinner.succeed(`Worker "${name}" deleted`);
|
|
66
61
|
console.log();
|
|
67
62
|
if (options.dev) {
|
|
68
|
-
|
|
63
|
+
logger.warning('Environment: development');
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
catch (error) {
|
|
72
|
-
const message = error instanceof Error ? error.message : '
|
|
73
|
-
|
|
67
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
68
|
+
logger.error(message);
|
|
74
69
|
process.exit(1);
|
|
75
70
|
}
|
|
76
71
|
});
|
|
72
|
+
addExamples(removeCommand, [
|
|
73
|
+
{ description: 'Delete a worker with confirmation prompt',
|
|
74
|
+
command: 'plazbot workers remove my-tool' },
|
|
75
|
+
{ description: 'Delete without confirmation (scripts/CI)',
|
|
76
|
+
command: 'plazbot workers remove my-tool -f' },
|
|
77
|
+
]);
|
|
77
78
|
function askConfirmation(question) {
|
|
78
79
|
return new Promise((resolve) => {
|
|
79
|
-
const rl =
|
|
80
|
+
const rl = readline.createInterface({
|
|
80
81
|
input: process.stdin,
|
|
81
82
|
output: process.stdout,
|
|
82
83
|
});
|
|
@@ -1,137 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const credentials_1 = require("../../utils/credentials");
|
|
9
|
-
const api_1 = require("../../utils/api");
|
|
10
|
-
const logger_1 = require("../../utils/logger");
|
|
11
|
-
const ui_1 = require("../../utils/ui");
|
|
12
|
-
const readline_1 = __importDefault(require("readline"));
|
|
1
|
+
import { Command } from 'commander';
|
|
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 readline from 'readline';
|
|
13
8
|
// ── Comando padre: secret ───────────────────────────────────────────────────
|
|
14
|
-
|
|
15
|
-
.description('
|
|
9
|
+
export const secretCommand = new Command('secret')
|
|
10
|
+
.description('Manage worker secrets (environment variables)')
|
|
16
11
|
.addCommand(secretSetCommand())
|
|
17
12
|
.addCommand(secretListCommand())
|
|
18
13
|
.addCommand(secretRemoveCommand());
|
|
14
|
+
addExamples(secretCommand, [
|
|
15
|
+
{ description: 'Save (or update) an API key as a secret',
|
|
16
|
+
command: 'plazbot workers secret set STRIPE_API_KEY sk_live_xxxxx' },
|
|
17
|
+
{ description: 'List every secret (values are hidden)',
|
|
18
|
+
command: 'plazbot workers secret list' },
|
|
19
|
+
{ description: 'Delete a secret with confirmation prompt',
|
|
20
|
+
command: 'plazbot workers secret remove STRIPE_API_KEY' },
|
|
21
|
+
{ description: 'Delete a secret without confirmation',
|
|
22
|
+
command: 'plazbot workers secret remove STRIPE_API_KEY -f' },
|
|
23
|
+
]);
|
|
19
24
|
// ── secret set ──────────────────────────────────────────────────────────────
|
|
20
25
|
function secretSetCommand() {
|
|
21
|
-
return new
|
|
22
|
-
.description('
|
|
23
|
-
.argument('<key>', '
|
|
24
|
-
.argument('<value>', '
|
|
25
|
-
.option('--dev', '
|
|
26
|
+
return new Command('set')
|
|
27
|
+
.description('Create or update a secret')
|
|
28
|
+
.argument('<key>', 'Secret name (e.g.: STRIPE_API_KEY)')
|
|
29
|
+
.argument('<value>', 'Secret value')
|
|
30
|
+
.option('--dev', 'Use development environment', false)
|
|
26
31
|
.action(async (key, value, options) => {
|
|
27
32
|
try {
|
|
28
|
-
const credentials = await
|
|
29
|
-
const api =
|
|
33
|
+
const credentials = await getStoredCredentials();
|
|
34
|
+
const api = createApiClient({
|
|
30
35
|
apiKey: credentials.apiKey,
|
|
31
36
|
workspace: credentials.workspace,
|
|
32
37
|
zone: credentials.zone,
|
|
33
38
|
dev: options.dev,
|
|
34
39
|
});
|
|
35
|
-
const spinner =
|
|
40
|
+
const spinner = createSpinner(`Saving secret "${key}"...`);
|
|
36
41
|
spinner.start();
|
|
37
42
|
await api.put('/api/worker/secrets', { key, value });
|
|
38
|
-
spinner.succeed(`Secret "${key}"
|
|
39
|
-
|
|
43
|
+
spinner.succeed(`Secret "${key}" saved`);
|
|
44
|
+
logger.dim(` Available in your workers as plz.env.${key}`);
|
|
40
45
|
console.log();
|
|
41
46
|
if (options.dev) {
|
|
42
|
-
|
|
47
|
+
logger.warning('Environment: development');
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
catch (error) {
|
|
46
|
-
const message = error instanceof Error ? error.message : '
|
|
47
|
-
|
|
51
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
52
|
+
logger.error(message);
|
|
48
53
|
process.exit(1);
|
|
49
54
|
}
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
57
|
// ── secret list ─────────────────────────────────────────────────────────────
|
|
53
58
|
function secretListCommand() {
|
|
54
|
-
return new
|
|
55
|
-
.description('
|
|
56
|
-
.option('--dev', '
|
|
59
|
+
return new Command('list')
|
|
60
|
+
.description('List all secrets in the workspace (without showing values)')
|
|
61
|
+
.option('--dev', 'Use development environment', false)
|
|
57
62
|
.action(async (options) => {
|
|
58
63
|
try {
|
|
59
|
-
const credentials = await
|
|
60
|
-
const api =
|
|
64
|
+
const credentials = await getStoredCredentials();
|
|
65
|
+
const api = createApiClient({
|
|
61
66
|
apiKey: credentials.apiKey,
|
|
62
67
|
workspace: credentials.workspace,
|
|
63
68
|
zone: credentials.zone,
|
|
64
69
|
dev: options.dev,
|
|
65
70
|
});
|
|
66
|
-
const spinner =
|
|
71
|
+
const spinner = createSpinner('Fetching secrets...');
|
|
67
72
|
spinner.start();
|
|
68
73
|
const response = await api.get('/api/worker/secrets');
|
|
69
74
|
const secrets = response.data;
|
|
70
75
|
spinner.stop();
|
|
71
76
|
if (!secrets || secrets.length === 0) {
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
logger.info('\n No secrets configured');
|
|
78
|
+
logger.dim(' Add one: plazbot workers secret set MY_KEY my_value');
|
|
74
79
|
console.log();
|
|
75
80
|
return;
|
|
76
81
|
}
|
|
77
|
-
|
|
82
|
+
logger.title(`Secrets (${secrets.length})`);
|
|
78
83
|
const rows = secrets.map(s => [
|
|
79
84
|
s.key,
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
theme.muted('••••••••'),
|
|
86
|
+
formatDate(s.updatedAt),
|
|
82
87
|
]);
|
|
83
|
-
console.log(
|
|
88
|
+
console.log(createTable(['Key', 'Value', 'Updated'], rows));
|
|
84
89
|
console.log();
|
|
85
90
|
if (options.dev) {
|
|
86
|
-
|
|
91
|
+
logger.warning('Environment: development');
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
catch (error) {
|
|
90
|
-
const message = error instanceof Error ? error.message : '
|
|
91
|
-
|
|
95
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
96
|
+
logger.error(message);
|
|
92
97
|
process.exit(1);
|
|
93
98
|
}
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
101
|
// ── secret remove ───────────────────────────────────────────────────────────
|
|
97
102
|
function secretRemoveCommand() {
|
|
98
|
-
return new
|
|
99
|
-
.description('
|
|
100
|
-
.argument('<key>', '
|
|
101
|
-
.option('-f, --force', '
|
|
102
|
-
.option('--dev', '
|
|
103
|
+
return new Command('remove')
|
|
104
|
+
.description('Delete a secret from the workspace')
|
|
105
|
+
.argument('<key>', 'Name of the secret to delete')
|
|
106
|
+
.option('-f, --force', 'Delete without confirmation', false)
|
|
107
|
+
.option('--dev', 'Use development environment', false)
|
|
103
108
|
.action(async (key, options) => {
|
|
104
109
|
try {
|
|
105
|
-
const credentials = await
|
|
106
|
-
const api =
|
|
110
|
+
const credentials = await getStoredCredentials();
|
|
111
|
+
const api = createApiClient({
|
|
107
112
|
apiKey: credentials.apiKey,
|
|
108
113
|
workspace: credentials.workspace,
|
|
109
114
|
zone: credentials.zone,
|
|
110
115
|
dev: options.dev,
|
|
111
116
|
});
|
|
112
117
|
if (!options.force) {
|
|
113
|
-
const confirmed = await askConfirmation(`
|
|
118
|
+
const confirmed = await askConfirmation(` Delete secret "${key}"? (y/N): `);
|
|
114
119
|
if (!confirmed) {
|
|
115
|
-
|
|
120
|
+
logger.info('\n Operation cancelled');
|
|
116
121
|
process.exit(0);
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
|
-
const spinner =
|
|
124
|
+
const spinner = createSpinner(`Deleting secret "${key}"...`);
|
|
120
125
|
spinner.start();
|
|
121
126
|
await api.delete(`/api/worker/secrets/${encodeURIComponent(key)}`);
|
|
122
|
-
spinner.succeed(`Secret "${key}"
|
|
127
|
+
spinner.succeed(`Secret "${key}" deleted`);
|
|
123
128
|
console.log();
|
|
124
129
|
if (options.dev) {
|
|
125
|
-
|
|
130
|
+
logger.warning('Environment: development');
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
catch (error) {
|
|
129
134
|
if (error.response?.status === 404) {
|
|
130
|
-
|
|
135
|
+
logger.error(`Secret "${key}" not found`);
|
|
131
136
|
}
|
|
132
137
|
else {
|
|
133
|
-
const message = error instanceof Error ? error.message : '
|
|
134
|
-
|
|
138
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
139
|
+
logger.error(message);
|
|
135
140
|
}
|
|
136
141
|
process.exit(1);
|
|
137
142
|
}
|
|
@@ -139,7 +144,7 @@ function secretRemoveCommand() {
|
|
|
139
144
|
}
|
|
140
145
|
function askConfirmation(question) {
|
|
141
146
|
return new Promise((resolve) => {
|
|
142
|
-
const rl =
|
|
147
|
+
const rl = readline.createInterface({
|
|
143
148
|
input: process.stdin,
|
|
144
149
|
output: process.stdout,
|
|
145
150
|
});
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
.
|
|
12
|
-
.option('
|
|
13
|
-
.option('
|
|
14
|
-
.option('--
|
|
15
|
-
.option('--agent <id>', 'ID del agente (contexto para tools)')
|
|
16
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
1
|
+
import { Command } from 'commander';
|
|
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';
|
|
7
|
+
export const testCommand = new Command('test')
|
|
8
|
+
.description('Run a worker manually to test it')
|
|
9
|
+
.argument('<name>', 'Name of the worker to run')
|
|
10
|
+
.option('-p, --payload <json>', 'JSON payload for the worker (e.g.: \'{"product":"iPhone"}\')')
|
|
11
|
+
.option('-t, --type <type>', 'Worker type (tool, worker, sync, schedule, webhook)')
|
|
12
|
+
.option('--contact <id>', 'Contact ID (context for tools)')
|
|
13
|
+
.option('--agent <id>', 'Agent ID (context for tools)')
|
|
14
|
+
.option('--dev', 'Use development environment', false)
|
|
17
15
|
.action(async (name, options) => {
|
|
18
16
|
try {
|
|
19
|
-
const credentials = await
|
|
20
|
-
const api =
|
|
17
|
+
const credentials = await getStoredCredentials();
|
|
18
|
+
const api = createApiClient({
|
|
21
19
|
apiKey: credentials.apiKey,
|
|
22
20
|
workspace: credentials.workspace,
|
|
23
21
|
zone: credentials.zone,
|
|
@@ -30,18 +28,18 @@ exports.testCommand = new commander_1.Command('test')
|
|
|
30
28
|
payload = JSON.parse(options.payload);
|
|
31
29
|
}
|
|
32
30
|
catch {
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
logger.error('Payload is not valid JSON');
|
|
32
|
+
logger.dim('Example: --payload \'{"product":"iPhone 15"}\'');
|
|
35
33
|
process.exit(1);
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
|
-
|
|
36
|
+
logger.title(`Running worker "${name}"`);
|
|
39
37
|
console.log();
|
|
40
38
|
if (Object.keys(payload).length > 0) {
|
|
41
|
-
|
|
39
|
+
logger.label('Payload', JSON.stringify(payload, null, 2));
|
|
42
40
|
console.log();
|
|
43
41
|
}
|
|
44
|
-
const spinner =
|
|
42
|
+
const spinner = createSpinner('Running...');
|
|
45
43
|
spinner.start();
|
|
46
44
|
const response = await api.post('/api/worker/execute', {
|
|
47
45
|
workerName: name,
|
|
@@ -55,28 +53,28 @@ exports.testCommand = new commander_1.Command('test')
|
|
|
55
53
|
const duration = data.duration ?? 0;
|
|
56
54
|
spinner.stop();
|
|
57
55
|
if (data.success) {
|
|
58
|
-
|
|
56
|
+
logger.success(`Completed in ${duration}ms`);
|
|
59
57
|
}
|
|
60
58
|
else {
|
|
61
|
-
|
|
59
|
+
logger.error(`Failed in ${duration}ms`);
|
|
62
60
|
}
|
|
63
61
|
console.log();
|
|
64
62
|
// Mostrar resultado
|
|
65
63
|
if (data.result !== undefined && data.result !== null) {
|
|
66
|
-
|
|
64
|
+
logger.label('Result', '');
|
|
67
65
|
const result = data.result;
|
|
68
66
|
// Si es un ToolResponse, mostrar formateado
|
|
69
67
|
if (typeof result === 'object' && 'result' in result) {
|
|
70
68
|
console.log();
|
|
71
|
-
|
|
69
|
+
logger.label(' result', theme.success(String(result.result)));
|
|
72
70
|
if (result.data) {
|
|
73
|
-
|
|
71
|
+
logger.label(' data', JSON.stringify(result.data, null, 2));
|
|
74
72
|
}
|
|
75
73
|
if (Array.isArray(result.actions) && result.actions.length > 0) {
|
|
76
|
-
|
|
74
|
+
logger.label(' actions', '');
|
|
77
75
|
for (const action of result.actions) {
|
|
78
76
|
const a = action;
|
|
79
|
-
|
|
77
|
+
logger.dim(` - ${a.type}: ${a.value}${a.code ? ` (${a.code})` : ''}`);
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
}
|
|
@@ -88,22 +86,32 @@ exports.testCommand = new commander_1.Command('test')
|
|
|
88
86
|
// Mostrar error si hubo
|
|
89
87
|
if (data.error) {
|
|
90
88
|
console.log();
|
|
91
|
-
|
|
89
|
+
logger.label('Error', theme.error(data.error));
|
|
92
90
|
}
|
|
93
91
|
console.log();
|
|
94
92
|
if (options.dev) {
|
|
95
|
-
|
|
93
|
+
logger.warning('Environment: development');
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
96
|
catch (error) {
|
|
99
97
|
if (error.response?.status === 404) {
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
logger.error(`Worker "${name}" not found or inactive`);
|
|
99
|
+
logger.dim('Verify the worker is deployed with: plazbot workers list');
|
|
102
100
|
}
|
|
103
101
|
else {
|
|
104
|
-
const message = error.response?.data?.message || error.message || '
|
|
105
|
-
|
|
102
|
+
const message = error.response?.data?.message || error.message || 'Unknown error';
|
|
103
|
+
logger.error(message);
|
|
106
104
|
}
|
|
107
105
|
process.exit(1);
|
|
108
106
|
}
|
|
109
107
|
});
|
|
108
|
+
addExamples(testCommand, [
|
|
109
|
+
{ description: 'Run a worker without payload',
|
|
110
|
+
command: 'plazbot workers test my-tool' },
|
|
111
|
+
{ description: 'Run a worker with a JSON payload',
|
|
112
|
+
command: 'plazbot workers test get-stock -p \'{"product":"iPhone 15"}\'' },
|
|
113
|
+
{ description: 'Run a tool with contact and agent context',
|
|
114
|
+
command: 'plazbot workers test my-tool --contact ctc_AbcDef123 --agent agt_AbcDef123' },
|
|
115
|
+
{ description: 'Run against the local backend',
|
|
116
|
+
command: 'plazbot workers test my-tool --dev' },
|
|
117
|
+
]);
|