plazbot-cli 0.3.7 → 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.
Files changed (116) hide show
  1. package/README.md +38 -2
  2. package/dist/commands/auth/browser-login.js +121 -0
  3. package/dist/commands/auth/index.js +5 -1
  4. package/dist/commands/auth/login.js +1 -3
  5. package/dist/commands/auth/logout.js +4 -3
  6. package/dist/commands/auth/status.js +8 -5
  7. package/dist/commands/auth/workspace.js +73 -0
  8. package/dist/commands/whatsapp/connect-flow.js +137 -0
  9. package/dist/commands/whatsapp/connect.js +26 -160
  10. package/dist/commands/whatsapp/index.js +4 -0
  11. package/dist/commands/whatsapp/setup.js +242 -0
  12. package/dist/studio/components/App.js +1 -1
  13. package/dist/studio/runOneShot.js +2 -2
  14. package/dist/studio/runRepl.js +1 -1
  15. package/dist/utils/agent-errors.js +2 -2
  16. package/dist/utils/banner.js +10 -9
  17. package/dist/utils/credentials.js +31 -3
  18. package/dist/utils/open-browser.js +17 -0
  19. package/package.json +14 -6
  20. package/.claude/settings.local.json +0 -19
  21. package/CLAUDE.md +0 -121
  22. package/agent.config.json +0 -21
  23. package/dist/studio/components/AgentPanel.js +0 -35
  24. package/dist/studio/render/json.js +0 -16
  25. package/dist/studio/whatsapp/api.js +0 -63
  26. package/dist/studio/whatsapp/polling.js +0 -77
  27. package/dist/studio/whatsapp/types.js +0 -31
  28. package/src/cli.ts +0 -57
  29. package/src/commands/agent/ai-config.ts +0 -164
  30. package/src/commands/agent/chat.ts +0 -225
  31. package/src/commands/agent/copy.ts +0 -46
  32. package/src/commands/agent/create.ts +0 -103
  33. package/src/commands/agent/delete.ts +0 -71
  34. package/src/commands/agent/enable-widget.ts +0 -67
  35. package/src/commands/agent/export.ts +0 -430
  36. package/src/commands/agent/files.ts +0 -171
  37. package/src/commands/agent/get.ts +0 -233
  38. package/src/commands/agent/index.ts +0 -55
  39. package/src/commands/agent/list.ts +0 -58
  40. package/src/commands/agent/monitor.ts +0 -375
  41. package/src/commands/agent/on-message.ts +0 -82
  42. package/src/commands/agent/set.ts +0 -149
  43. package/src/commands/agent/templates.ts +0 -892
  44. package/src/commands/agent/tools.ts +0 -168
  45. package/src/commands/agent/update.ts +0 -61
  46. package/src/commands/agent/validate.ts +0 -135
  47. package/src/commands/agent/wizard.ts +0 -756
  48. package/src/commands/auth/index.ts +0 -10
  49. package/src/commands/auth/login.ts +0 -72
  50. package/src/commands/auth/logout.ts +0 -28
  51. package/src/commands/auth/status.ts +0 -28
  52. package/src/commands/portal/add-agent.ts +0 -66
  53. package/src/commands/portal/add-link.ts +0 -47
  54. package/src/commands/portal/clear-links.ts +0 -33
  55. package/src/commands/portal/create.ts +0 -58
  56. package/src/commands/portal/delete.ts +0 -70
  57. package/src/commands/portal/get.ts +0 -77
  58. package/src/commands/portal/index.ts +0 -32
  59. package/src/commands/portal/list.ts +0 -79
  60. package/src/commands/portal/update.ts +0 -93
  61. package/src/commands/whatsapp/broadcast.ts +0 -110
  62. package/src/commands/whatsapp/channels.ts +0 -109
  63. package/src/commands/whatsapp/chat.ts +0 -85
  64. package/src/commands/whatsapp/connect.ts +0 -220
  65. package/src/commands/whatsapp/delete-webhook.ts +0 -43
  66. package/src/commands/whatsapp/index.ts +0 -37
  67. package/src/commands/whatsapp/register-webhook.ts +0 -47
  68. package/src/commands/whatsapp/send-template.ts +0 -94
  69. package/src/commands/whatsapp/send.ts +0 -55
  70. package/src/commands/whatsapp/widget.ts +0 -75
  71. package/src/commands/workers/deploy.ts +0 -156
  72. package/src/commands/workers/index.ts +0 -30
  73. package/src/commands/workers/list.ts +0 -105
  74. package/src/commands/workers/logs.ts +0 -99
  75. package/src/commands/workers/remove.ts +0 -103
  76. package/src/commands/workers/secret.ts +0 -191
  77. package/src/commands/workers/test.ts +0 -145
  78. package/src/schemas/agent.config.schema.json +0 -569
  79. package/src/studio/api/sseClient.ts +0 -91
  80. package/src/studio/api/studioApi.ts +0 -27
  81. package/src/studio/api/types.ts +0 -96
  82. package/src/studio/components/App.tsx +0 -274
  83. package/src/studio/components/ChatLog.tsx +0 -121
  84. package/src/studio/components/ConnectCard.tsx +0 -171
  85. package/src/studio/components/Footer.tsx +0 -38
  86. package/src/studio/components/Header.tsx +0 -39
  87. package/src/studio/components/Input.tsx +0 -176
  88. package/src/studio/components/Message.tsx +0 -87
  89. package/src/studio/components/Suggestions.tsx +0 -26
  90. package/src/studio/components/ToolCall.tsx +0 -58
  91. package/src/studio/connect/api.ts +0 -98
  92. package/src/studio/connect/polling.ts +0 -94
  93. package/src/studio/connect/types.ts +0 -141
  94. package/src/studio/index.ts +0 -58
  95. package/src/studio/render/markdown.ts +0 -93
  96. package/src/studio/render/steps.ts +0 -57
  97. package/src/studio/runOneShot.ts +0 -114
  98. package/src/studio/runRepl.tsx +0 -82
  99. package/src/studio/slash/handlers.ts +0 -226
  100. package/src/studio/slash/parser.ts +0 -41
  101. package/src/studio/slash/registry.ts +0 -54
  102. package/src/studio/state/store.ts +0 -279
  103. package/src/types/agent.ts +0 -63
  104. package/src/types/auth.ts +0 -9
  105. package/src/types/common.ts +0 -10
  106. package/src/types/message.ts +0 -34
  107. package/src/types/portal.ts +0 -56
  108. package/src/types/workers.ts +0 -86
  109. package/src/utils/agent-errors.ts +0 -67
  110. package/src/utils/api.ts +0 -35
  111. package/src/utils/banner.ts +0 -99
  112. package/src/utils/credentials.ts +0 -38
  113. package/src/utils/help.ts +0 -51
  114. package/src/utils/logger.ts +0 -40
  115. package/src/utils/ui.ts +0 -109
  116. package/tsconfig.json +0 -18
@@ -1,225 +0,0 @@
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 { describeAgentLoadError } from '../../utils/agent-errors.js';
7
- import { AgentCommandOptions, AgentResponse, AgentSource } from '../../types/agent.js';
8
- import { theme, section } from '../../utils/ui.js';
9
- import crypto from 'crypto';
10
- import readline from 'readline';
11
- import chalk from 'chalk';
12
-
13
- const COMMANDS_HELP = `
14
- ${chalk.bold('Available commands:')}
15
- ${chalk.hex('#4CAF50')('/exit')} End conversation
16
- ${chalk.hex('#4CAF50')('/clear')} Clear screen
17
- ${chalk.hex('#4CAF50')('/info')} Session information
18
- ${chalk.hex('#4CAF50')('/sources')} Toggle sources
19
- ${chalk.hex('#4CAF50')('/help')} Show these commands
20
- `;
21
-
22
- export const chatCommand = new Command('chat')
23
- .description('Start an interactive chat session with an agent')
24
- .argument('<agentId>', 'Agent ID')
25
- .option('-s, --session-id <id>', 'Session ID (optional)')
26
- .option('-m, --multiple-answers', 'Allow multiple answers', false)
27
- .option('--dev', 'Use development environment', false)
28
- .action(async (agentId: string, options: AgentCommandOptions & {
29
- sessionId?: string;
30
- multipleAnswers?: boolean;
31
- }) => {
32
- try {
33
- const credentials = await getStoredCredentials();
34
-
35
- const agent = new Agent({
36
- workspaceId: credentials.workspace,
37
- apiKey: credentials.apiKey,
38
- zone: credentials.zone,
39
- ...(options.dev && { customUrl: "http://localhost:5090" })
40
- });
41
-
42
- const sessionId = options.sessionId || crypto.randomUUID();
43
- let showSources = true;
44
-
45
- // Cargar info del agente
46
- let agentInfo: any = null;
47
- try {
48
- process.stdout.write(chalk.gray(' Connecting to agent...'));
49
- const _res: any = await agent.getAgentById({ id: agentId });
50
- agentInfo = _res.agent || _res.data || _res;
51
- process.stdout.write('\r' + ' '.repeat(40) + '\r');
52
- } catch (loadErr) {
53
- process.stdout.write('\r' + ' '.repeat(40) + '\r');
54
- logger.error(describeAgentLoadError(loadErr, agentId, credentials, { dev: options.dev }));
55
- process.exit(1);
56
- }
57
-
58
- const rl = readline.createInterface({
59
- input: process.stdin,
60
- output: process.stdout
61
- });
62
-
63
- // Pantalla de chat
64
- console.clear();
65
- const agentName = agentInfo?.name || 'Agent';
66
- const toolCalling = agentInfo?.useToolCalling ? chalk.hex('#4CAF50')(' [Tool Calling]') : '';
67
-
68
- console.log();
69
- console.log(chalk.hex('#4CAF50')(' ┌' + '─'.repeat(58) + '┐'));
70
- console.log(chalk.hex('#4CAF50')(' │') + chalk.bold(` ${agentName}${toolCalling}`).padEnd(68) + chalk.hex('#4CAF50')('│'));
71
- console.log(chalk.hex('#4CAF50')(' │') + chalk.gray(` Session: ${sessionId.substring(0, 8)}...`).padEnd(68) + chalk.hex('#4CAF50')('│'));
72
- console.log(chalk.hex('#4CAF50')(' │') + chalk.gray(' /help to see commands').padEnd(68) + chalk.hex('#4CAF50')('│'));
73
- console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(58) + '┘'));
74
- console.log();
75
-
76
- // Saludo del agente
77
- if (agentInfo?.instructions?.greeting) {
78
- const timestamp = new Date().toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
79
- console.log(chalk.hex('#4CAF50')(` ${agentName}`) + chalk.gray(` ${timestamp}`));
80
- console.log(chalk.white(` ${agentInfo.instructions.greeting}`));
81
- console.log();
82
- }
83
-
84
- const askQuestion = () => {
85
- rl.question(chalk.hex('#2196F3')(' You > '), async (question) => {
86
- if (!question.trim()) {
87
- askQuestion();
88
- return;
89
- }
90
-
91
- // Comandos especiales
92
- if (question.toLowerCase() === '/exit') {
93
- console.log(chalk.gray('\n Session ended.\n'));
94
- rl.close();
95
- return;
96
- }
97
-
98
- if (question.toLowerCase() === '/clear') {
99
- console.clear();
100
- askQuestion();
101
- return;
102
- }
103
-
104
- if (question.toLowerCase() === '/help') {
105
- console.log(COMMANDS_HELP);
106
- askQuestion();
107
- return;
108
- }
109
-
110
- if (question.toLowerCase() === '/info') {
111
- console.log(section('Session information'));
112
- logger.label('Agent ID', agentId);
113
- logger.label('Session ID', sessionId);
114
- logger.label('Agent', agentName);
115
- logger.label('Tool Calling', agentInfo?.useToolCalling ? 'Enabled' : 'Disabled');
116
- logger.label('AI Provider', agentInfo?.customAIConfig ? (agentInfo.aiProviders?.[0]?.provider || 'Custom') : 'Default');
117
- console.log();
118
- askQuestion();
119
- return;
120
- }
121
-
122
- if (question.toLowerCase() === '/sources') {
123
- showSources = !showSources;
124
- console.log(chalk.gray(` Sources: ${showSources ? 'on' : 'off'}`));
125
- console.log();
126
- askQuestion();
127
- return;
128
- }
129
-
130
- try {
131
- process.stdout.write(chalk.gray(' ...thinking\n'));
132
-
133
- const response = await agent.onMessage({
134
- agentId: agentId,
135
- question,
136
- sessionId,
137
- multipleAnswers: options.multipleAnswers
138
- }) as AgentResponse & { actionsExecuted?: any[] };
139
-
140
- const timestamp = new Date().toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
141
-
142
- // Mostrar tool calls si hay
143
- if (response.actionsExecuted && response.actionsExecuted.length > 0) {
144
- response.actionsExecuted.forEach((action: any) => {
145
- console.log(chalk.hex('#FFA726')(` Tool: ${action.name || action.intent || 'action'}`));
146
- });
147
- }
148
-
149
- // Respuesta del agente
150
- console.log();
151
- console.log(chalk.hex('#4CAF50')(` ${agentName}`) + chalk.gray(` ${timestamp}`));
152
-
153
- // Formatear respuesta (soporte basico de markdown)
154
- const formattedAnswer = formatResponse(response.answer);
155
- console.log(formattedAnswer);
156
- console.log();
157
-
158
- // Fuentes
159
- if (showSources && response.sources && response.sources.length > 0) {
160
- console.log(chalk.gray(' Sources:'));
161
- response.sources.forEach((source: AgentSource) => {
162
- console.log(chalk.gray(` - ${source.title || 'Untitled'}`));
163
- if (source.url) console.log(chalk.gray(` ${source.url}`));
164
- });
165
- console.log();
166
- }
167
-
168
- askQuestion();
169
- } catch (error) {
170
- const message = error instanceof Error ? error.message : 'Unknown error';
171
- console.log(chalk.hex('#EF5350')(`\n ✖ Error: ${message}\n`));
172
- askQuestion();
173
- }
174
- });
175
- };
176
-
177
- askQuestion();
178
-
179
- } catch (error) {
180
- const message = error instanceof Error ? error.message : 'Unknown error';
181
- logger.error(message);
182
- process.exit(1);
183
- }
184
- });
185
-
186
- addExamples(chatCommand, [
187
- { description: 'Open an interactive chat with the agent',
188
- command: 'plazbot agent chat agt_AbcDef123' },
189
- { description: 'Reuse a previous session ID to continue the conversation',
190
- command: 'plazbot agent chat agt_AbcDef123 -s sess_AbcDef123' },
191
- { description: 'Allow the agent to send multiple answers per turn',
192
- command: 'plazbot agent chat agt_AbcDef123 -m' },
193
- ]);
194
-
195
- function formatResponse(text: string): string {
196
- if (!text) return '';
197
-
198
- return text.split('\n').map(line => {
199
- // Headers
200
- if (line.startsWith('### ')) return chalk.bold.hex('#4CAF50')(' ' + line.substring(4));
201
- if (line.startsWith('## ')) return chalk.bold.hex('#4CAF50')(' ' + line.substring(3));
202
- if (line.startsWith('# ')) return chalk.bold.hex('#4CAF50')(' ' + line.substring(2));
203
-
204
- // Bold
205
- line = line.replace(/\*\*(.*?)\*\*/g, (_, text) => chalk.bold(text));
206
-
207
- // Italic
208
- line = line.replace(/\*(.*?)\*/g, (_, text) => chalk.italic(text));
209
-
210
- // Code inline
211
- line = line.replace(/`(.*?)`/g, (_, text) => chalk.hex('#FFA726')(text));
212
-
213
- // List items
214
- if (line.match(/^\s*[-*]\s/)) {
215
- return chalk.white(' ' + line.replace(/^\s*[-*]\s/, ' • '));
216
- }
217
-
218
- // Numbered lists
219
- if (line.match(/^\s*\d+\.\s/)) {
220
- return chalk.white(' ' + line);
221
- }
222
-
223
- return chalk.white(' ' + line);
224
- }).join('\n');
225
- }
@@ -1,46 +0,0 @@
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 { AgentCommandOptions } from '../../types/agent.js';
8
-
9
- export const copyCommand = new Command('copy')
10
- .description('Clone an existing agent')
11
- .argument('<agentId>', 'Agent ID to clone')
12
- .option('--dev', 'Use development environment', false)
13
- .action(async (agentId: string, options: AgentCommandOptions) => {
14
- try {
15
- const credentials = await getStoredCredentials();
16
- const agent = new Agent({
17
- workspaceId: credentials.workspace,
18
- apiKey: credentials.apiKey,
19
- zone: credentials.zone,
20
- ...(options.dev && { customUrl: "http://localhost:5090" })
21
- });
22
-
23
- const spinner = createSpinner('Cloning agent...');
24
- spinner.start();
25
-
26
- const result = await (agent as any).copyAgent({ id: agentId });
27
-
28
- spinner.succeed('Agent cloned successfully');
29
-
30
- logger.title('Cloned agent');
31
- if (result?.agentId || result?.id) {
32
- logger.label('New ID', result.agentId || result.id);
33
- }
34
- logger.dim('\nThe cloned agent has the widget disabled by default.');
35
-
36
- } catch (error) {
37
- const message = error instanceof Error ? error.message : 'Unknown error';
38
- logger.error(message);
39
- process.exit(1);
40
- }
41
- });
42
-
43
- addExamples(copyCommand, [
44
- { description: 'Clone an agent (widget stays disabled on the copy)',
45
- command: 'plazbot agent copy agt_AbcDef123' },
46
- ]);
@@ -1,103 +0,0 @@
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 { AgentCommandOptions } from '../../types/agent.js';
7
- import { createSpinner } from '../../utils/ui.js';
8
- import { runAgentWizard } from './wizard.js';
9
- import fs from 'fs/promises';
10
-
11
- export const createCommand = new Command('create')
12
- .description('Create a new AI agent (interactive wizard or JSON file)')
13
- .argument('[configPath]', 'Path to the JSON config file (optional)')
14
- .option('--dev', 'Use development environment', false)
15
- .action(async (configPath: string | undefined, options: AgentCommandOptions) => {
16
- try {
17
- const credentials = await getStoredCredentials();
18
-
19
- const agent = new Agent({
20
- workspaceId: credentials.workspace,
21
- apiKey: credentials.apiKey,
22
- zone: credentials.zone,
23
- ...(options.dev && { customUrl: "http://localhost:5090" })
24
- });
25
-
26
- let agentConfig: any;
27
-
28
- if (configPath) {
29
- // Modo archivo: leer JSON
30
- try {
31
- const fileContent = await fs.readFile(configPath, 'utf-8');
32
- agentConfig = JSON.parse(fileContent);
33
- } catch (error) {
34
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
35
- throw new Error(`Failed to read config file: ${errorMessage}`);
36
- }
37
- logger.title('Creating agent from file');
38
- logger.json(agentConfig);
39
- } else {
40
- // Modo wizard interactivo
41
- agentConfig = await runAgentWizard(credentials.zone, credentials.workspace, credentials.apiKey, options.dev);
42
-
43
- const inquirer = await import('inquirer');
44
- const { confirm } = await inquirer.default.prompt([{
45
- type: 'confirm',
46
- name: 'confirm',
47
- message: 'Create the agent with this configuration?',
48
- default: true,
49
- }]);
50
-
51
- if (!confirm) {
52
- logger.warning('Creation cancelled');
53
- return;
54
- }
55
- }
56
-
57
- const spinner = createSpinner('Creating agent...');
58
- spinner.start();
59
-
60
- const result = await agent.addAgent(agentConfig);
61
-
62
- spinner.succeed('Agent created successfully');
63
-
64
- logger.title('Agent details');
65
- if (result.agentId) {
66
- logger.label('ID', result.agentId);
67
- }
68
- if (agentConfig.name) {
69
- logger.label('Name', agentConfig.name);
70
- }
71
- logger.label('Tool Calling', agentConfig.useToolCalling ? 'Enabled' : 'Disabled');
72
-
73
- if (agentConfig.channels && agentConfig.channels.length > 0) {
74
- agentConfig.channels.forEach((ch: any) => {
75
- logger.label(`Channel (${ch.channel})`, ch.key);
76
- });
77
- }
78
-
79
- console.log();
80
- logger.dim('Next step: plazbot agent chat -a ' + (result.agentId || '<agentId>'));
81
- console.log();
82
-
83
- if (options.dev) {
84
- logger.warning('Environment: development');
85
- }
86
-
87
- process.exit(0);
88
-
89
- } catch (error) {
90
- const message = error instanceof Error ? error.message : 'Unknown error while creating the agent';
91
- logger.error(message);
92
- process.exit(1);
93
- }
94
- });
95
-
96
- addExamples(createCommand, [
97
- { description: 'Launch the interactive wizard to design the agent',
98
- command: 'plazbot agent create' },
99
- { description: 'Create directly from a JSON configuration file',
100
- command: 'plazbot agent create ./agent.json' },
101
- { description: 'Create against a local backend (dev mode)',
102
- command: 'plazbot agent create ./agent.json --dev' },
103
- ]);
@@ -1,71 +0,0 @@
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 { AgentCommandOptions } from '../../types/agent.js';
7
- import readline from 'readline';
8
-
9
- export const deleteCommand = new Command('delete')
10
- .description('Delete an existing agent')
11
- .argument('<agentId>', 'Agent ID to delete')
12
- .option('--dev', 'Use development environment', false)
13
- .action(async (agentId: string, options: AgentCommandOptions) => {
14
- try {
15
- // Obtener credenciales guardadas
16
- const credentials = await getStoredCredentials();
17
-
18
- const agent = new Agent({
19
- workspaceId: credentials.workspace,
20
- apiKey: credentials.apiKey,
21
- zone: credentials.zone,
22
- ...(options.dev && { customUrl: "http://localhost:5090" })
23
- });
24
-
25
- // Obtener detalles del agente para mostrar información
26
- const response: any = await agent.getAgentById({ id: agentId });
27
- const agentDetails = response.agent || response.data || response;
28
-
29
- logger.warning('\nYou are about to delete the following agent:');
30
- logger.divider();
31
- logger.info(`ID: ${agentDetails.id || agentId}`);
32
- logger.info(`Name: ${agentDetails.name || '—'}`);
33
- logger.info(`Description: ${agentDetails.description || '—'}`);
34
- logger.divider();
35
-
36
- // Crear interfaz para confirmación
37
- const rl = readline.createInterface({
38
- input: process.stdin,
39
- output: process.stdout
40
- });
41
-
42
- // Preguntar por confirmación
43
- rl.question('\nAre you sure you want to delete this agent? (y/N): ', async (answer) => {
44
- if (answer.toLowerCase() === 'y') {
45
- await agent.deleteAgent({
46
- id: agentId
47
- });
48
-
49
- logger.success('Agent deleted successfully');
50
-
51
- if (options.dev) {
52
- logger.warning('Environment: development');
53
- }
54
- } else {
55
- logger.error('Operation cancelled');
56
- }
57
-
58
- rl.close();
59
- });
60
-
61
- } catch (error) {
62
- const message = error instanceof Error ? error.message : 'Unknown error while deleting the agent';
63
- logger.error(message);
64
- process.exit(1);
65
- }
66
- });
67
-
68
- addExamples(deleteCommand, [
69
- { description: 'Delete an agent (asks for y/N confirmation)',
70
- command: 'plazbot agent delete agt_AbcDef123' },
71
- ]);
@@ -1,67 +0,0 @@
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 { EnableWidgetOptions } from '../../types/agent.js';
7
-
8
- export const enableCommand = new Command('enable-widget')
9
- .description('Enable or disable an agent widget')
10
- .argument('<agentId>', 'Agent ID')
11
- .option('-d, --disable', 'Disable the widget instead of enabling it')
12
- .option('--dev', 'Use development environment', false)
13
- .action(async (agentId: string, options: EnableWidgetOptions) => {
14
- try {
15
- // Obtener credenciales guardadas
16
- const credentials = await getStoredCredentials();
17
-
18
- const agent = new Agent({
19
- workspaceId: credentials.workspace,
20
- apiKey: credentials.apiKey,
21
- zone: credentials.zone,
22
- ...(options.dev && { customUrl: "http://localhost:5090" })
23
- });
24
-
25
- // Obtener estado actual del agente
26
- const _res: any = await agent.getAgentById({ id: agentId });
27
- const agentDetails = _res.agent || _res.data || _res;
28
-
29
- logger.title('Current widget status');
30
- logger.label('Agent', agentDetails.name);
31
-
32
- // Cambiar estado
33
- const newState = !options.disable; // Si --disable está presente, newState será false
34
- const result = await agent.enableWidget({
35
- id: agentId,
36
- enable: newState
37
- });
38
-
39
- logger.success(`Widget ${newState ? 'enabled' : 'disabled'} successfully`);
40
-
41
- logger.title('Server response');
42
- logger.label('Status', result.success ? 'Success' : 'Failed');
43
- logger.label('Message', result.message);
44
-
45
- if (newState && result.script) {
46
- logger.title('Installation instructions');
47
- logger.dim('Place this script under the <HEAD> tag of your website:');
48
- logger.info('\n' + result.script);
49
- }
50
-
51
- if (options.dev) {
52
- logger.warning('Environment: development');
53
- }
54
-
55
- } catch (error) {
56
- const message = error instanceof Error ? error.message : 'Unknown error while updating the widget';
57
- logger.error(message);
58
- process.exit(1);
59
- }
60
- });
61
-
62
- addExamples(enableCommand, [
63
- { description: 'Enable the widget and print the <script> snippet',
64
- command: 'plazbot agent enable-widget agt_AbcDef123' },
65
- { description: 'Disable an existing widget',
66
- command: 'plazbot agent enable-widget agt_AbcDef123 --disable' },
67
- ]);