plazbot-cli 0.3.6 → 0.4.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.
- package/README.md +38 -2
- package/dist/commands/agent/export.js +25 -2
- package/dist/commands/auth/browser-login.js +121 -0
- package/dist/commands/auth/index.js +5 -1
- package/dist/commands/auth/login.js +1 -3
- package/dist/commands/auth/logout.js +4 -3
- package/dist/commands/auth/status.js +8 -5
- package/dist/commands/auth/workspace.js +73 -0
- package/dist/commands/whatsapp/connect-flow.js +137 -0
- package/dist/commands/whatsapp/connect.js +26 -160
- package/dist/commands/whatsapp/index.js +4 -0
- package/dist/commands/whatsapp/setup.js +242 -0
- package/dist/studio/components/App.js +1 -1
- package/dist/studio/runOneShot.js +2 -2
- package/dist/studio/runRepl.js +1 -1
- package/dist/utils/agent-errors.js +2 -2
- package/dist/utils/banner.js +10 -9
- package/dist/utils/credentials.js +31 -3
- package/dist/utils/open-browser.js +17 -0
- package/package.json +14 -6
- package/.claude/settings.local.json +0 -15
- package/CLAUDE.md +0 -121
- package/agent.config.json +0 -21
- package/dist/studio/components/AgentPanel.js +0 -35
- package/dist/studio/render/json.js +0 -16
- package/dist/studio/whatsapp/api.js +0 -63
- package/dist/studio/whatsapp/polling.js +0 -77
- package/dist/studio/whatsapp/types.js +0 -31
- package/src/cli.ts +0 -57
- package/src/commands/agent/ai-config.ts +0 -164
- package/src/commands/agent/chat.ts +0 -225
- package/src/commands/agent/copy.ts +0 -46
- package/src/commands/agent/create.ts +0 -103
- package/src/commands/agent/delete.ts +0 -71
- package/src/commands/agent/enable-widget.ts +0 -67
- package/src/commands/agent/export.ts +0 -408
- package/src/commands/agent/files.ts +0 -171
- package/src/commands/agent/get.ts +0 -233
- package/src/commands/agent/index.ts +0 -55
- package/src/commands/agent/list.ts +0 -58
- package/src/commands/agent/monitor.ts +0 -375
- package/src/commands/agent/on-message.ts +0 -82
- package/src/commands/agent/set.ts +0 -149
- package/src/commands/agent/templates.ts +0 -892
- package/src/commands/agent/tools.ts +0 -168
- package/src/commands/agent/update.ts +0 -61
- package/src/commands/agent/validate.ts +0 -135
- package/src/commands/agent/wizard.ts +0 -756
- package/src/commands/auth/index.ts +0 -10
- package/src/commands/auth/login.ts +0 -72
- package/src/commands/auth/logout.ts +0 -28
- package/src/commands/auth/status.ts +0 -28
- package/src/commands/portal/add-agent.ts +0 -66
- package/src/commands/portal/add-link.ts +0 -47
- package/src/commands/portal/clear-links.ts +0 -33
- package/src/commands/portal/create.ts +0 -58
- package/src/commands/portal/delete.ts +0 -70
- package/src/commands/portal/get.ts +0 -77
- package/src/commands/portal/index.ts +0 -32
- package/src/commands/portal/list.ts +0 -79
- package/src/commands/portal/update.ts +0 -93
- package/src/commands/whatsapp/broadcast.ts +0 -110
- package/src/commands/whatsapp/channels.ts +0 -109
- package/src/commands/whatsapp/chat.ts +0 -85
- package/src/commands/whatsapp/connect.ts +0 -220
- package/src/commands/whatsapp/delete-webhook.ts +0 -43
- package/src/commands/whatsapp/index.ts +0 -37
- package/src/commands/whatsapp/register-webhook.ts +0 -47
- package/src/commands/whatsapp/send-template.ts +0 -94
- package/src/commands/whatsapp/send.ts +0 -55
- package/src/commands/whatsapp/widget.ts +0 -75
- package/src/commands/workers/deploy.ts +0 -156
- package/src/commands/workers/index.ts +0 -30
- package/src/commands/workers/list.ts +0 -105
- package/src/commands/workers/logs.ts +0 -99
- package/src/commands/workers/remove.ts +0 -103
- package/src/commands/workers/secret.ts +0 -191
- package/src/commands/workers/test.ts +0 -145
- package/src/schemas/agent.config.schema.json +0 -569
- package/src/studio/api/sseClient.ts +0 -91
- package/src/studio/api/studioApi.ts +0 -27
- package/src/studio/api/types.ts +0 -96
- package/src/studio/components/App.tsx +0 -274
- package/src/studio/components/ChatLog.tsx +0 -121
- package/src/studio/components/ConnectCard.tsx +0 -171
- package/src/studio/components/Footer.tsx +0 -38
- package/src/studio/components/Header.tsx +0 -39
- package/src/studio/components/Input.tsx +0 -176
- package/src/studio/components/Message.tsx +0 -87
- package/src/studio/components/Suggestions.tsx +0 -26
- package/src/studio/components/ToolCall.tsx +0 -58
- package/src/studio/connect/api.ts +0 -98
- package/src/studio/connect/polling.ts +0 -94
- package/src/studio/connect/types.ts +0 -141
- package/src/studio/index.ts +0 -58
- package/src/studio/render/markdown.ts +0 -93
- package/src/studio/render/steps.ts +0 -57
- package/src/studio/runOneShot.ts +0 -114
- package/src/studio/runRepl.tsx +0 -82
- package/src/studio/slash/handlers.ts +0 -226
- package/src/studio/slash/parser.ts +0 -41
- package/src/studio/slash/registry.ts +0 -54
- package/src/studio/state/store.ts +0 -279
- package/src/types/agent.ts +0 -63
- package/src/types/auth.ts +0 -9
- package/src/types/common.ts +0 -10
- package/src/types/message.ts +0 -34
- package/src/types/portal.ts +0 -56
- package/src/types/workers.ts +0 -86
- package/src/utils/agent-errors.ts +0 -67
- package/src/utils/api.ts +0 -35
- package/src/utils/banner.ts +0 -99
- package/src/utils/credentials.ts +0 -38
- package/src/utils/help.ts +0 -51
- package/src/utils/logger.ts +0 -40
- package/src/utils/ui.ts +0 -109
- package/tsconfig.json +0 -18
|
@@ -1,99 +0,0 @@
|
|
|
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 { WorkerLogsOptions, WorkerLogItem } from '../../types/workers.js';
|
|
8
|
-
|
|
9
|
-
export const logsCommand = new Command('logs')
|
|
10
|
-
.description('View execution logs for a worker')
|
|
11
|
-
.argument('<name>', 'Worker name')
|
|
12
|
-
.option('-l, --limit <number>', 'Number of logs to display', '20')
|
|
13
|
-
.option('-s, --status <status>', 'Filter by status (success, error, timeout)')
|
|
14
|
-
.option('--dev', 'Use development environment', false)
|
|
15
|
-
.action(async (name: string, options: WorkerLogsOptions) => {
|
|
16
|
-
try {
|
|
17
|
-
const credentials = await getStoredCredentials();
|
|
18
|
-
const api = createApiClient({
|
|
19
|
-
apiKey: credentials.apiKey,
|
|
20
|
-
workspace: credentials.workspace,
|
|
21
|
-
zone: credentials.zone,
|
|
22
|
-
dev: options.dev,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const spinner = createSpinner(`Fetching logs for "${name}"...`);
|
|
26
|
-
spinner.start();
|
|
27
|
-
|
|
28
|
-
const params: Record<string, string> = {
|
|
29
|
-
limit: String(options.limit || 20),
|
|
30
|
-
};
|
|
31
|
-
if (options.status) params.status = options.status;
|
|
32
|
-
|
|
33
|
-
const response = await api.get(`/api/worker/${encodeURIComponent(name)}/logs`, { params });
|
|
34
|
-
const logs: WorkerLogItem[] = response.data;
|
|
35
|
-
|
|
36
|
-
spinner.stop();
|
|
37
|
-
|
|
38
|
-
if (!logs || logs.length === 0) {
|
|
39
|
-
logger.info(`\n No logs found for "${name}"`);
|
|
40
|
-
console.log();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
logger.title(`Logs for "${name}" (${logs.length})`);
|
|
45
|
-
|
|
46
|
-
const rows = logs.map(log => [
|
|
47
|
-
formatDate(log.createdAt),
|
|
48
|
-
log.status === 'success' ? theme.success('ok')
|
|
49
|
-
: log.status === 'error' ? theme.error('error')
|
|
50
|
-
: theme.warning('timeout'),
|
|
51
|
-
`${log.durationMs}ms`,
|
|
52
|
-
log.triggerSource || '—',
|
|
53
|
-
log.error ? theme.error(truncate(log.error, 40)) : '—',
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
console.log(createTable(
|
|
57
|
-
['Date', 'Status', 'Duration', 'Source', 'Error'],
|
|
58
|
-
rows,
|
|
59
|
-
));
|
|
60
|
-
|
|
61
|
-
// Resumen
|
|
62
|
-
const successCount = logs.filter(l => l.status === 'success').length;
|
|
63
|
-
const errorCount = logs.filter(l => l.status === 'error').length;
|
|
64
|
-
const avgDuration = Math.round(logs.reduce((sum, l) => sum + l.durationMs, 0) / logs.length);
|
|
65
|
-
|
|
66
|
-
console.log();
|
|
67
|
-
logger.label('Successful', theme.success(`${successCount}`));
|
|
68
|
-
logger.label('Errors', errorCount > 0 ? theme.error(`${errorCount}`) : theme.muted('0'));
|
|
69
|
-
logger.label('Average duration', `${avgDuration}ms`);
|
|
70
|
-
console.log();
|
|
71
|
-
|
|
72
|
-
if (options.dev) {
|
|
73
|
-
logger.warning('Environment: development');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
} catch (error: any) {
|
|
77
|
-
if (error.response?.status === 404) {
|
|
78
|
-
logger.error(`Worker "${name}" not found`);
|
|
79
|
-
} else {
|
|
80
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
81
|
-
logger.error(message);
|
|
82
|
-
}
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
addExamples(logsCommand, [
|
|
88
|
-
{ description: 'Show the last 20 executions of a worker',
|
|
89
|
-
command: 'plazbot workers logs my-tool' },
|
|
90
|
-
{ description: 'Get the last 100 executions',
|
|
91
|
-
command: 'plazbot workers logs my-tool -l 100' },
|
|
92
|
-
{ description: 'Only show failed executions',
|
|
93
|
-
command: 'plazbot workers logs my-tool -s error' },
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
function truncate(text: string, max: number): string {
|
|
97
|
-
if (text.length <= max) return text;
|
|
98
|
-
return text.substring(0, max - 3) + '...';
|
|
99
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
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 { WorkerRemoveOptions } from '../../types/workers.js';
|
|
8
|
-
import readline from 'readline';
|
|
9
|
-
|
|
10
|
-
export const removeCommand = new Command('remove')
|
|
11
|
-
.description('Delete a worker from the workspace')
|
|
12
|
-
.argument('<name>', 'Name of the worker to delete')
|
|
13
|
-
.option('-f, --force', 'Delete without confirmation', false)
|
|
14
|
-
.option('--dev', 'Use development environment', false)
|
|
15
|
-
.action(async (name: string, options: WorkerRemoveOptions) => {
|
|
16
|
-
try {
|
|
17
|
-
const credentials = await getStoredCredentials();
|
|
18
|
-
const api = createApiClient({
|
|
19
|
-
apiKey: credentials.apiKey,
|
|
20
|
-
workspace: credentials.workspace,
|
|
21
|
-
zone: credentials.zone,
|
|
22
|
-
dev: options.dev,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Verificar que el worker existe
|
|
26
|
-
const spinner = createSpinner(`Looking up worker "${name}"...`);
|
|
27
|
-
spinner.start();
|
|
28
|
-
|
|
29
|
-
let workerInfo: any;
|
|
30
|
-
try {
|
|
31
|
-
const response = await api.get(`/api/worker/${encodeURIComponent(name)}`);
|
|
32
|
-
workerInfo = response.data;
|
|
33
|
-
spinner.stop();
|
|
34
|
-
} catch (error: any) {
|
|
35
|
-
spinner.stop();
|
|
36
|
-
if (error.response?.status === 404) {
|
|
37
|
-
logger.error(`Worker "${name}" not found`);
|
|
38
|
-
} else {
|
|
39
|
-
logger.error(error.response?.data?.message || error.message);
|
|
40
|
-
}
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Mostrar info del worker
|
|
45
|
-
logger.warning(`\n You are about to delete the following worker:`);
|
|
46
|
-
logger.divider();
|
|
47
|
-
logger.label('Name', workerInfo.name);
|
|
48
|
-
logger.label('Type', workerInfo.type);
|
|
49
|
-
logger.label('Status', workerInfo.status);
|
|
50
|
-
logger.label('Executions', `${workerInfo.executionCount || 0}`);
|
|
51
|
-
logger.divider();
|
|
52
|
-
|
|
53
|
-
// Confirmacion
|
|
54
|
-
if (!options.force) {
|
|
55
|
-
const confirmed = await askConfirmation(
|
|
56
|
-
`Delete worker "${name}"? This action cannot be undone (y/N): `
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
if (!confirmed) {
|
|
60
|
-
logger.info('\n Operation cancelled');
|
|
61
|
-
process.exit(0);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const deleteSpinner = createSpinner(`Deleting "${name}"...`);
|
|
66
|
-
deleteSpinner.start();
|
|
67
|
-
|
|
68
|
-
await api.delete(`/api/worker/${encodeURIComponent(name)}`);
|
|
69
|
-
|
|
70
|
-
deleteSpinner.succeed(`Worker "${name}" deleted`);
|
|
71
|
-
console.log();
|
|
72
|
-
|
|
73
|
-
if (options.dev) {
|
|
74
|
-
logger.warning('Environment: development');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
} catch (error) {
|
|
78
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
79
|
-
logger.error(message);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
addExamples(removeCommand, [
|
|
85
|
-
{ description: 'Delete a worker with confirmation prompt',
|
|
86
|
-
command: 'plazbot workers remove my-tool' },
|
|
87
|
-
{ description: 'Delete without confirmation (scripts/CI)',
|
|
88
|
-
command: 'plazbot workers remove my-tool -f' },
|
|
89
|
-
]);
|
|
90
|
-
|
|
91
|
-
function askConfirmation(question: string): Promise<boolean> {
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
const rl = readline.createInterface({
|
|
94
|
-
input: process.stdin,
|
|
95
|
-
output: process.stdout,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
rl.question(question, (answer) => {
|
|
99
|
-
rl.close();
|
|
100
|
-
resolve(answer.toLowerCase() === 'y');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
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 { WorkerSecretItem } from '../../types/workers.js';
|
|
8
|
-
import readline from 'readline';
|
|
9
|
-
|
|
10
|
-
// ── Comando padre: secret ───────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
export const secretCommand = new Command('secret')
|
|
13
|
-
.description('Manage worker secrets (environment variables)')
|
|
14
|
-
.addCommand(secretSetCommand())
|
|
15
|
-
.addCommand(secretListCommand())
|
|
16
|
-
.addCommand(secretRemoveCommand());
|
|
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
|
-
|
|
29
|
-
// ── secret set ──────────────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
function secretSetCommand(): Command {
|
|
32
|
-
return new Command('set')
|
|
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)
|
|
37
|
-
.action(async (key: string, value: string, options: { dev?: boolean }) => {
|
|
38
|
-
try {
|
|
39
|
-
const credentials = await getStoredCredentials();
|
|
40
|
-
const api = createApiClient({
|
|
41
|
-
apiKey: credentials.apiKey,
|
|
42
|
-
workspace: credentials.workspace,
|
|
43
|
-
zone: credentials.zone,
|
|
44
|
-
dev: options.dev,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const spinner = createSpinner(`Saving secret "${key}"...`);
|
|
48
|
-
spinner.start();
|
|
49
|
-
|
|
50
|
-
await api.put('/api/worker/secrets', { key, value });
|
|
51
|
-
|
|
52
|
-
spinner.succeed(`Secret "${key}" saved`);
|
|
53
|
-
logger.dim(` Available in your workers as plz.env.${key}`);
|
|
54
|
-
console.log();
|
|
55
|
-
|
|
56
|
-
if (options.dev) {
|
|
57
|
-
logger.warning('Environment: development');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
} catch (error) {
|
|
61
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
62
|
-
logger.error(message);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ── secret list ─────────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
function secretListCommand(): Command {
|
|
71
|
-
return new Command('list')
|
|
72
|
-
.description('List all secrets in the workspace (without showing values)')
|
|
73
|
-
.option('--dev', 'Use development environment', false)
|
|
74
|
-
.action(async (options: { dev?: boolean }) => {
|
|
75
|
-
try {
|
|
76
|
-
const credentials = await getStoredCredentials();
|
|
77
|
-
const api = createApiClient({
|
|
78
|
-
apiKey: credentials.apiKey,
|
|
79
|
-
workspace: credentials.workspace,
|
|
80
|
-
zone: credentials.zone,
|
|
81
|
-
dev: options.dev,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const spinner = createSpinner('Fetching secrets...');
|
|
85
|
-
spinner.start();
|
|
86
|
-
|
|
87
|
-
const response = await api.get('/api/worker/secrets');
|
|
88
|
-
const secrets: WorkerSecretItem[] = response.data;
|
|
89
|
-
|
|
90
|
-
spinner.stop();
|
|
91
|
-
|
|
92
|
-
if (!secrets || secrets.length === 0) {
|
|
93
|
-
logger.info('\n No secrets configured');
|
|
94
|
-
logger.dim(' Add one: plazbot workers secret set MY_KEY my_value');
|
|
95
|
-
console.log();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
logger.title(`Secrets (${secrets.length})`);
|
|
100
|
-
|
|
101
|
-
const rows = secrets.map(s => [
|
|
102
|
-
s.key,
|
|
103
|
-
theme.muted('••••••••'),
|
|
104
|
-
formatDate(s.updatedAt),
|
|
105
|
-
]);
|
|
106
|
-
|
|
107
|
-
console.log(createTable(
|
|
108
|
-
['Key', 'Value', 'Updated'],
|
|
109
|
-
rows,
|
|
110
|
-
));
|
|
111
|
-
|
|
112
|
-
console.log();
|
|
113
|
-
|
|
114
|
-
if (options.dev) {
|
|
115
|
-
logger.warning('Environment: development');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
} catch (error) {
|
|
119
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
120
|
-
logger.error(message);
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// ── secret remove ───────────────────────────────────────────────────────────
|
|
127
|
-
|
|
128
|
-
function secretRemoveCommand(): Command {
|
|
129
|
-
return new Command('remove')
|
|
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)
|
|
134
|
-
.action(async (key: string, options: { dev?: boolean; force?: boolean }) => {
|
|
135
|
-
try {
|
|
136
|
-
const credentials = await getStoredCredentials();
|
|
137
|
-
const api = createApiClient({
|
|
138
|
-
apiKey: credentials.apiKey,
|
|
139
|
-
workspace: credentials.workspace,
|
|
140
|
-
zone: credentials.zone,
|
|
141
|
-
dev: options.dev,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
if (!options.force) {
|
|
145
|
-
const confirmed = await askConfirmation(
|
|
146
|
-
` Delete secret "${key}"? (y/N): `
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
if (!confirmed) {
|
|
150
|
-
logger.info('\n Operation cancelled');
|
|
151
|
-
process.exit(0);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const spinner = createSpinner(`Deleting secret "${key}"...`);
|
|
156
|
-
spinner.start();
|
|
157
|
-
|
|
158
|
-
await api.delete(`/api/worker/secrets/${encodeURIComponent(key)}`);
|
|
159
|
-
|
|
160
|
-
spinner.succeed(`Secret "${key}" deleted`);
|
|
161
|
-
console.log();
|
|
162
|
-
|
|
163
|
-
if (options.dev) {
|
|
164
|
-
logger.warning('Environment: development');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
} catch (error: any) {
|
|
168
|
-
if (error.response?.status === 404) {
|
|
169
|
-
logger.error(`Secret "${key}" not found`);
|
|
170
|
-
} else {
|
|
171
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
172
|
-
logger.error(message);
|
|
173
|
-
}
|
|
174
|
-
process.exit(1);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function askConfirmation(question: string): Promise<boolean> {
|
|
180
|
-
return new Promise((resolve) => {
|
|
181
|
-
const rl = readline.createInterface({
|
|
182
|
-
input: process.stdin,
|
|
183
|
-
output: process.stdout,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
rl.question(question, (answer) => {
|
|
187
|
-
rl.close();
|
|
188
|
-
resolve(answer.toLowerCase() === 'y');
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
interface WorkerTestResult {
|
|
9
|
-
success: boolean;
|
|
10
|
-
result?: unknown;
|
|
11
|
-
error?: string;
|
|
12
|
-
duration?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const testCommand = new Command('test')
|
|
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)
|
|
23
|
-
.action(async (name: string, options: {
|
|
24
|
-
payload?: string;
|
|
25
|
-
type?: string;
|
|
26
|
-
contact?: string;
|
|
27
|
-
agent?: string;
|
|
28
|
-
dev?: boolean;
|
|
29
|
-
}) => {
|
|
30
|
-
try {
|
|
31
|
-
const credentials = await getStoredCredentials();
|
|
32
|
-
const api = createApiClient({
|
|
33
|
-
apiKey: credentials.apiKey,
|
|
34
|
-
workspace: credentials.workspace,
|
|
35
|
-
zone: credentials.zone,
|
|
36
|
-
dev: options.dev,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Parsear payload
|
|
40
|
-
let payload: Record<string, unknown> = {};
|
|
41
|
-
if (options.payload) {
|
|
42
|
-
try {
|
|
43
|
-
payload = JSON.parse(options.payload);
|
|
44
|
-
} catch {
|
|
45
|
-
logger.error('Payload is not valid JSON');
|
|
46
|
-
logger.dim('Example: --payload \'{"product":"iPhone 15"}\'');
|
|
47
|
-
process.exit(1);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
logger.title(`Running worker "${name}"`);
|
|
52
|
-
console.log();
|
|
53
|
-
|
|
54
|
-
if (Object.keys(payload).length > 0) {
|
|
55
|
-
logger.label('Payload', JSON.stringify(payload, null, 2));
|
|
56
|
-
console.log();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const spinner = createSpinner('Running...');
|
|
60
|
-
spinner.start();
|
|
61
|
-
|
|
62
|
-
const response = await api.post('/api/worker/execute', {
|
|
63
|
-
workerName: name,
|
|
64
|
-
type: options.type,
|
|
65
|
-
payload,
|
|
66
|
-
triggerSource: 'cli-test',
|
|
67
|
-
agentId: options.agent,
|
|
68
|
-
contactId: options.contact,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const data = response.data as WorkerTestResult;
|
|
72
|
-
const duration = data.duration ?? 0;
|
|
73
|
-
|
|
74
|
-
spinner.stop();
|
|
75
|
-
|
|
76
|
-
if (data.success) {
|
|
77
|
-
logger.success(`Completed in ${duration}ms`);
|
|
78
|
-
} else {
|
|
79
|
-
logger.error(`Failed in ${duration}ms`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
console.log();
|
|
83
|
-
|
|
84
|
-
// Mostrar resultado
|
|
85
|
-
if (data.result !== undefined && data.result !== null) {
|
|
86
|
-
logger.label('Result', '');
|
|
87
|
-
|
|
88
|
-
const result = data.result as Record<string, unknown>;
|
|
89
|
-
|
|
90
|
-
// Si es un ToolResponse, mostrar formateado
|
|
91
|
-
if (typeof result === 'object' && 'result' in result) {
|
|
92
|
-
console.log();
|
|
93
|
-
logger.label(' result', theme.success(String(result.result)));
|
|
94
|
-
|
|
95
|
-
if (result.data) {
|
|
96
|
-
logger.label(' data', JSON.stringify(result.data, null, 2));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (Array.isArray(result.actions) && result.actions.length > 0) {
|
|
100
|
-
logger.label(' actions', '');
|
|
101
|
-
for (const action of result.actions) {
|
|
102
|
-
const a = action as Record<string, string>;
|
|
103
|
-
logger.dim(` - ${a.type}: ${a.value}${a.code ? ` (${a.code})` : ''}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
// Resultado generico
|
|
108
|
-
console.log(JSON.stringify(result, null, 2));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Mostrar error si hubo
|
|
113
|
-
if (data.error) {
|
|
114
|
-
console.log();
|
|
115
|
-
logger.label('Error', theme.error(data.error));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
console.log();
|
|
119
|
-
|
|
120
|
-
if (options.dev) {
|
|
121
|
-
logger.warning('Environment: development');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
} catch (error: any) {
|
|
125
|
-
if (error.response?.status === 404) {
|
|
126
|
-
logger.error(`Worker "${name}" not found or inactive`);
|
|
127
|
-
logger.dim('Verify the worker is deployed with: plazbot workers list');
|
|
128
|
-
} else {
|
|
129
|
-
const message = error.response?.data?.message || error.message || 'Unknown error';
|
|
130
|
-
logger.error(message);
|
|
131
|
-
}
|
|
132
|
-
process.exit(1);
|
|
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
|
-
]);
|