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,37 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
.argument('<agentId>', 'ID del agente a clonar')
|
|
12
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
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
|
+
export const copyCommand = new Command('copy')
|
|
8
|
+
.description('Clone an existing agent')
|
|
9
|
+
.argument('<agentId>', 'Agent ID to clone')
|
|
10
|
+
.option('--dev', 'Use development environment', false)
|
|
13
11
|
.action(async (agentId, options) => {
|
|
14
12
|
try {
|
|
15
|
-
const credentials = await
|
|
16
|
-
const agent = new
|
|
13
|
+
const credentials = await getStoredCredentials();
|
|
14
|
+
const agent = new Agent({
|
|
17
15
|
workspaceId: credentials.workspace,
|
|
18
16
|
apiKey: credentials.apiKey,
|
|
19
17
|
zone: credentials.zone,
|
|
20
18
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
21
19
|
});
|
|
22
|
-
const spinner =
|
|
20
|
+
const spinner = createSpinner('Cloning agent...');
|
|
23
21
|
spinner.start();
|
|
24
22
|
const result = await agent.copyAgent({ id: agentId });
|
|
25
|
-
spinner.succeed('
|
|
26
|
-
|
|
23
|
+
spinner.succeed('Agent cloned successfully');
|
|
24
|
+
logger.title('Cloned agent');
|
|
27
25
|
if (result?.agentId || result?.id) {
|
|
28
|
-
|
|
26
|
+
logger.label('New ID', result.agentId || result.id);
|
|
29
27
|
}
|
|
30
|
-
|
|
28
|
+
logger.dim('\nThe cloned agent has the widget disabled by default.');
|
|
31
29
|
}
|
|
32
30
|
catch (error) {
|
|
33
|
-
const message = error instanceof Error ? error.message : '
|
|
34
|
-
|
|
31
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
32
|
+
logger.error(message);
|
|
35
33
|
process.exit(1);
|
|
36
34
|
}
|
|
37
35
|
});
|
|
36
|
+
addExamples(copyCommand, [
|
|
37
|
+
{ description: 'Clone an agent (widget stays disabled on the copy)',
|
|
38
|
+
command: 'plazbot agent copy agt_AbcDef123' },
|
|
39
|
+
]);
|
|
@@ -1,57 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.createCommand = void 0;
|
|
40
|
-
const commander_1 = require("commander");
|
|
41
|
-
const plazbot_1 = require("plazbot");
|
|
42
|
-
const credentials_1 = require("../../utils/credentials");
|
|
43
|
-
const logger_1 = require("../../utils/logger");
|
|
44
|
-
const ui_1 = require("../../utils/ui");
|
|
45
|
-
const wizard_1 = require("./wizard");
|
|
46
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
47
|
-
exports.createCommand = new commander_1.Command('create')
|
|
48
|
-
.description('Crea un nuevo agente de IA (wizard interactivo o archivo JSON)')
|
|
49
|
-
.argument('[configPath]', 'Ruta al archivo de configuracion JSON (opcional)')
|
|
50
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
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 { runAgentWizard } from './wizard.js';
|
|
8
|
+
import fs from 'fs/promises';
|
|
9
|
+
export const createCommand = new Command('create')
|
|
10
|
+
.description('Create a new AI agent (interactive wizard or JSON file)')
|
|
11
|
+
.argument('[configPath]', 'Path to the JSON config file (optional)')
|
|
12
|
+
.option('--dev', 'Use development environment', false)
|
|
51
13
|
.action(async (configPath, options) => {
|
|
52
14
|
try {
|
|
53
|
-
const credentials = await
|
|
54
|
-
const agent = new
|
|
15
|
+
const credentials = await getStoredCredentials();
|
|
16
|
+
const agent = new Agent({
|
|
55
17
|
workspaceId: credentials.workspace,
|
|
56
18
|
apiKey: credentials.apiKey,
|
|
57
19
|
zone: credentials.zone,
|
|
@@ -61,59 +23,67 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
61
23
|
if (configPath) {
|
|
62
24
|
// Modo archivo: leer JSON
|
|
63
25
|
try {
|
|
64
|
-
const fileContent = await
|
|
26
|
+
const fileContent = await fs.readFile(configPath, 'utf-8');
|
|
65
27
|
agentConfig = JSON.parse(fileContent);
|
|
66
28
|
}
|
|
67
29
|
catch (error) {
|
|
68
|
-
const errorMessage = error instanceof Error ? error.message : '
|
|
69
|
-
throw new Error(`
|
|
30
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
31
|
+
throw new Error(`Failed to read config file: ${errorMessage}`);
|
|
70
32
|
}
|
|
71
|
-
|
|
72
|
-
|
|
33
|
+
logger.title('Creating agent from file');
|
|
34
|
+
logger.json(agentConfig);
|
|
73
35
|
}
|
|
74
36
|
else {
|
|
75
37
|
// Modo wizard interactivo
|
|
76
|
-
agentConfig = await
|
|
77
|
-
const inquirer = await
|
|
38
|
+
agentConfig = await runAgentWizard(credentials.zone, credentials.workspace, credentials.apiKey, options.dev);
|
|
39
|
+
const inquirer = await import('inquirer');
|
|
78
40
|
const { confirm } = await inquirer.default.prompt([{
|
|
79
41
|
type: 'confirm',
|
|
80
42
|
name: 'confirm',
|
|
81
|
-
message: '
|
|
43
|
+
message: 'Create the agent with this configuration?',
|
|
82
44
|
default: true,
|
|
83
45
|
}]);
|
|
84
46
|
if (!confirm) {
|
|
85
|
-
|
|
47
|
+
logger.warning('Creation cancelled');
|
|
86
48
|
return;
|
|
87
49
|
}
|
|
88
50
|
}
|
|
89
|
-
const spinner =
|
|
51
|
+
const spinner = createSpinner('Creating agent...');
|
|
90
52
|
spinner.start();
|
|
91
53
|
const result = await agent.addAgent(agentConfig);
|
|
92
|
-
spinner.succeed('
|
|
93
|
-
|
|
54
|
+
spinner.succeed('Agent created successfully');
|
|
55
|
+
logger.title('Agent details');
|
|
94
56
|
if (result.agentId) {
|
|
95
|
-
|
|
57
|
+
logger.label('ID', result.agentId);
|
|
96
58
|
}
|
|
97
59
|
if (agentConfig.name) {
|
|
98
|
-
|
|
60
|
+
logger.label('Name', agentConfig.name);
|
|
99
61
|
}
|
|
100
|
-
|
|
62
|
+
logger.label('Tool Calling', agentConfig.useToolCalling ? 'Enabled' : 'Disabled');
|
|
101
63
|
if (agentConfig.channels && agentConfig.channels.length > 0) {
|
|
102
64
|
agentConfig.channels.forEach((ch) => {
|
|
103
|
-
|
|
65
|
+
logger.label(`Channel (${ch.channel})`, ch.key);
|
|
104
66
|
});
|
|
105
67
|
}
|
|
106
68
|
console.log();
|
|
107
|
-
|
|
69
|
+
logger.dim('Next step: plazbot agent chat -a ' + (result.agentId || '<agentId>'));
|
|
108
70
|
console.log();
|
|
109
71
|
if (options.dev) {
|
|
110
|
-
|
|
72
|
+
logger.warning('Environment: development');
|
|
111
73
|
}
|
|
112
74
|
process.exit(0);
|
|
113
75
|
}
|
|
114
76
|
catch (error) {
|
|
115
|
-
const message = error instanceof Error ? error.message : '
|
|
116
|
-
|
|
77
|
+
const message = error instanceof Error ? error.message : 'Unknown error while creating the agent';
|
|
78
|
+
logger.error(message);
|
|
117
79
|
process.exit(1);
|
|
118
80
|
}
|
|
119
81
|
});
|
|
82
|
+
addExamples(createCommand, [
|
|
83
|
+
{ description: 'Launch the interactive wizard to design the agent',
|
|
84
|
+
command: 'plazbot agent create' },
|
|
85
|
+
{ description: 'Create directly from a JSON configuration file',
|
|
86
|
+
command: 'plazbot agent create ./agent.json' },
|
|
87
|
+
{ description: 'Create against a local backend (dev mode)',
|
|
88
|
+
command: 'plazbot agent create ./agent.json --dev' },
|
|
89
|
+
]);
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const readline_1 = __importDefault(require("readline"));
|
|
12
|
-
exports.deleteCommand = new commander_1.Command('delete')
|
|
13
|
-
.description('Elimina un agente existente')
|
|
14
|
-
.argument('<agentId>', 'ID del agente a eliminar')
|
|
15
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
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 readline from 'readline';
|
|
7
|
+
export const deleteCommand = new Command('delete')
|
|
8
|
+
.description('Delete an existing agent')
|
|
9
|
+
.argument('<agentId>', 'Agent ID to delete')
|
|
10
|
+
.option('--dev', 'Use development environment', false)
|
|
16
11
|
.action(async (agentId, options) => {
|
|
17
12
|
try {
|
|
18
13
|
// Obtener credenciales guardadas
|
|
19
|
-
const credentials = await
|
|
20
|
-
const agent = new
|
|
14
|
+
const credentials = await getStoredCredentials();
|
|
15
|
+
const agent = new Agent({
|
|
21
16
|
workspaceId: credentials.workspace,
|
|
22
17
|
apiKey: credentials.apiKey,
|
|
23
18
|
zone: credentials.zone,
|
|
@@ -26,37 +21,41 @@ exports.deleteCommand = new commander_1.Command('delete')
|
|
|
26
21
|
// Obtener detalles del agente para mostrar información
|
|
27
22
|
const response = await agent.getAgentById({ id: agentId });
|
|
28
23
|
const agentDetails = response.agent || response.data || response;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
logger.warning('\nYou are about to delete the following agent:');
|
|
25
|
+
logger.divider();
|
|
26
|
+
logger.info(`ID: ${agentDetails.id || agentId}`);
|
|
27
|
+
logger.info(`Name: ${agentDetails.name || '—'}`);
|
|
28
|
+
logger.info(`Description: ${agentDetails.description || '—'}`);
|
|
29
|
+
logger.divider();
|
|
35
30
|
// Crear interfaz para confirmación
|
|
36
|
-
const rl =
|
|
31
|
+
const rl = readline.createInterface({
|
|
37
32
|
input: process.stdin,
|
|
38
33
|
output: process.stdout
|
|
39
34
|
});
|
|
40
35
|
// Preguntar por confirmación
|
|
41
|
-
rl.question('\
|
|
36
|
+
rl.question('\nAre you sure you want to delete this agent? (y/N): ', async (answer) => {
|
|
42
37
|
if (answer.toLowerCase() === 'y') {
|
|
43
38
|
await agent.deleteAgent({
|
|
44
39
|
id: agentId
|
|
45
40
|
});
|
|
46
|
-
|
|
41
|
+
logger.success('Agent deleted successfully');
|
|
47
42
|
if (options.dev) {
|
|
48
|
-
|
|
43
|
+
logger.warning('Environment: development');
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
else {
|
|
52
|
-
|
|
47
|
+
logger.error('Operation cancelled');
|
|
53
48
|
}
|
|
54
49
|
rl.close();
|
|
55
50
|
});
|
|
56
51
|
}
|
|
57
52
|
catch (error) {
|
|
58
|
-
const message = error instanceof Error ? error.message : '
|
|
59
|
-
|
|
53
|
+
const message = error instanceof Error ? error.message : 'Unknown error while deleting the agent';
|
|
54
|
+
logger.error(message);
|
|
60
55
|
process.exit(1);
|
|
61
56
|
}
|
|
62
57
|
});
|
|
58
|
+
addExamples(deleteCommand, [
|
|
59
|
+
{ description: 'Delete an agent (asks for y/N confirmation)',
|
|
60
|
+
command: 'plazbot agent delete agt_AbcDef123' },
|
|
61
|
+
]);
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
.option('-d, --disable', 'Deshabilitar el widget en lugar de habilitarlo')
|
|
12
|
-
.option('--dev', 'Usar ambiente de desarrollo', false)
|
|
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
|
+
export const enableCommand = new Command('enable-widget')
|
|
7
|
+
.description('Enable or disable an agent widget')
|
|
8
|
+
.argument('<agentId>', 'Agent ID')
|
|
9
|
+
.option('-d, --disable', 'Disable the widget instead of enabling it')
|
|
10
|
+
.option('--dev', 'Use development environment', false)
|
|
13
11
|
.action(async (agentId, options) => {
|
|
14
12
|
try {
|
|
15
13
|
// Obtener credenciales guardadas
|
|
16
|
-
const credentials = await
|
|
17
|
-
const agent = new
|
|
14
|
+
const credentials = await getStoredCredentials();
|
|
15
|
+
const agent = new Agent({
|
|
18
16
|
workspaceId: credentials.workspace,
|
|
19
17
|
apiKey: credentials.apiKey,
|
|
20
18
|
zone: credentials.zone,
|
|
@@ -23,30 +21,36 @@ exports.enableCommand = new commander_1.Command('enable-widget')
|
|
|
23
21
|
// Obtener estado actual del agente
|
|
24
22
|
const _res = await agent.getAgentById({ id: agentId });
|
|
25
23
|
const agentDetails = _res.agent || _res.data || _res;
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
logger.title('Current widget status');
|
|
25
|
+
logger.label('Agent', agentDetails.name);
|
|
28
26
|
// Cambiar estado
|
|
29
27
|
const newState = !options.disable; // Si --disable está presente, newState será false
|
|
30
28
|
const result = await agent.enableWidget({
|
|
31
29
|
id: agentId,
|
|
32
30
|
enable: newState
|
|
33
31
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
logger.success(`Widget ${newState ? 'enabled' : 'disabled'} successfully`);
|
|
33
|
+
logger.title('Server response');
|
|
34
|
+
logger.label('Status', result.success ? 'Success' : 'Failed');
|
|
35
|
+
logger.label('Message', result.message);
|
|
38
36
|
if (newState && result.script) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
logger.title('Installation instructions');
|
|
38
|
+
logger.dim('Place this script under the <HEAD> tag of your website:');
|
|
39
|
+
logger.info('\n' + result.script);
|
|
42
40
|
}
|
|
43
41
|
if (options.dev) {
|
|
44
|
-
|
|
42
|
+
logger.warning('Environment: development');
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
catch (error) {
|
|
48
|
-
const message = error instanceof Error ? error.message : '
|
|
49
|
-
|
|
46
|
+
const message = error instanceof Error ? error.message : 'Unknown error while updating the widget';
|
|
47
|
+
logger.error(message);
|
|
50
48
|
process.exit(1);
|
|
51
49
|
}
|
|
52
50
|
});
|
|
51
|
+
addExamples(enableCommand, [
|
|
52
|
+
{ description: 'Enable the widget and print the <script> snippet',
|
|
53
|
+
command: 'plazbot agent enable-widget agt_AbcDef123' },
|
|
54
|
+
{ description: 'Disable an existing widget',
|
|
55
|
+
command: 'plazbot agent enable-widget agt_AbcDef123 --disable' },
|
|
56
|
+
]);
|