plazbot-cli 0.3.7 → 0.4.1

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 (117) 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/schemas/agent.config.schema.json +24 -0
  13. package/dist/studio/components/App.js +1 -1
  14. package/dist/studio/runOneShot.js +2 -2
  15. package/dist/studio/runRepl.js +1 -1
  16. package/dist/utils/agent-errors.js +2 -2
  17. package/dist/utils/banner.js +10 -9
  18. package/dist/utils/credentials.js +31 -3
  19. package/dist/utils/open-browser.js +17 -0
  20. package/package.json +14 -6
  21. package/.claude/settings.local.json +0 -19
  22. package/CLAUDE.md +0 -121
  23. package/agent.config.json +0 -21
  24. package/dist/studio/components/AgentPanel.js +0 -35
  25. package/dist/studio/render/json.js +0 -16
  26. package/dist/studio/whatsapp/api.js +0 -63
  27. package/dist/studio/whatsapp/polling.js +0 -77
  28. package/dist/studio/whatsapp/types.js +0 -31
  29. package/src/cli.ts +0 -57
  30. package/src/commands/agent/ai-config.ts +0 -164
  31. package/src/commands/agent/chat.ts +0 -225
  32. package/src/commands/agent/copy.ts +0 -46
  33. package/src/commands/agent/create.ts +0 -103
  34. package/src/commands/agent/delete.ts +0 -71
  35. package/src/commands/agent/enable-widget.ts +0 -67
  36. package/src/commands/agent/export.ts +0 -430
  37. package/src/commands/agent/files.ts +0 -171
  38. package/src/commands/agent/get.ts +0 -233
  39. package/src/commands/agent/index.ts +0 -55
  40. package/src/commands/agent/list.ts +0 -58
  41. package/src/commands/agent/monitor.ts +0 -375
  42. package/src/commands/agent/on-message.ts +0 -82
  43. package/src/commands/agent/set.ts +0 -149
  44. package/src/commands/agent/templates.ts +0 -892
  45. package/src/commands/agent/tools.ts +0 -168
  46. package/src/commands/agent/update.ts +0 -61
  47. package/src/commands/agent/validate.ts +0 -135
  48. package/src/commands/agent/wizard.ts +0 -756
  49. package/src/commands/auth/index.ts +0 -10
  50. package/src/commands/auth/login.ts +0 -72
  51. package/src/commands/auth/logout.ts +0 -28
  52. package/src/commands/auth/status.ts +0 -28
  53. package/src/commands/portal/add-agent.ts +0 -66
  54. package/src/commands/portal/add-link.ts +0 -47
  55. package/src/commands/portal/clear-links.ts +0 -33
  56. package/src/commands/portal/create.ts +0 -58
  57. package/src/commands/portal/delete.ts +0 -70
  58. package/src/commands/portal/get.ts +0 -77
  59. package/src/commands/portal/index.ts +0 -32
  60. package/src/commands/portal/list.ts +0 -79
  61. package/src/commands/portal/update.ts +0 -93
  62. package/src/commands/whatsapp/broadcast.ts +0 -110
  63. package/src/commands/whatsapp/channels.ts +0 -109
  64. package/src/commands/whatsapp/chat.ts +0 -85
  65. package/src/commands/whatsapp/connect.ts +0 -220
  66. package/src/commands/whatsapp/delete-webhook.ts +0 -43
  67. package/src/commands/whatsapp/index.ts +0 -37
  68. package/src/commands/whatsapp/register-webhook.ts +0 -47
  69. package/src/commands/whatsapp/send-template.ts +0 -94
  70. package/src/commands/whatsapp/send.ts +0 -55
  71. package/src/commands/whatsapp/widget.ts +0 -75
  72. package/src/commands/workers/deploy.ts +0 -156
  73. package/src/commands/workers/index.ts +0 -30
  74. package/src/commands/workers/list.ts +0 -105
  75. package/src/commands/workers/logs.ts +0 -99
  76. package/src/commands/workers/remove.ts +0 -103
  77. package/src/commands/workers/secret.ts +0 -191
  78. package/src/commands/workers/test.ts +0 -145
  79. package/src/schemas/agent.config.schema.json +0 -569
  80. package/src/studio/api/sseClient.ts +0 -91
  81. package/src/studio/api/studioApi.ts +0 -27
  82. package/src/studio/api/types.ts +0 -96
  83. package/src/studio/components/App.tsx +0 -274
  84. package/src/studio/components/ChatLog.tsx +0 -121
  85. package/src/studio/components/ConnectCard.tsx +0 -171
  86. package/src/studio/components/Footer.tsx +0 -38
  87. package/src/studio/components/Header.tsx +0 -39
  88. package/src/studio/components/Input.tsx +0 -176
  89. package/src/studio/components/Message.tsx +0 -87
  90. package/src/studio/components/Suggestions.tsx +0 -26
  91. package/src/studio/components/ToolCall.tsx +0 -58
  92. package/src/studio/connect/api.ts +0 -98
  93. package/src/studio/connect/polling.ts +0 -94
  94. package/src/studio/connect/types.ts +0 -141
  95. package/src/studio/index.ts +0 -58
  96. package/src/studio/render/markdown.ts +0 -93
  97. package/src/studio/render/steps.ts +0 -57
  98. package/src/studio/runOneShot.ts +0 -114
  99. package/src/studio/runRepl.tsx +0 -82
  100. package/src/studio/slash/handlers.ts +0 -226
  101. package/src/studio/slash/parser.ts +0 -41
  102. package/src/studio/slash/registry.ts +0 -54
  103. package/src/studio/state/store.ts +0 -279
  104. package/src/types/agent.ts +0 -63
  105. package/src/types/auth.ts +0 -9
  106. package/src/types/common.ts +0 -10
  107. package/src/types/message.ts +0 -34
  108. package/src/types/portal.ts +0 -56
  109. package/src/types/workers.ts +0 -86
  110. package/src/utils/agent-errors.ts +0 -67
  111. package/src/utils/api.ts +0 -35
  112. package/src/utils/banner.ts +0 -99
  113. package/src/utils/credentials.ts +0 -38
  114. package/src/utils/help.ts +0 -51
  115. package/src/utils/logger.ts +0 -40
  116. package/src/utils/ui.ts +0 -109
  117. package/tsconfig.json +0 -18
@@ -1,164 +0,0 @@
1
- import { Command } from 'commander';
2
- import { Agent } from 'plazbot';
3
- import inquirer from 'inquirer';
4
- import { getStoredCredentials } from '../../utils/credentials.js';
5
- import { logger } from '../../utils/logger.js';
6
- import { addExamples } from '../../utils/help.js';
7
- import { describeAgentLoadError } from '../../utils/agent-errors.js';
8
- import { createSpinner, theme, section, kvPair } from '../../utils/ui.js';
9
- import { AgentCommandOptions } from '../../types/agent.js';
10
-
11
- // Catalogo de modelos sincronizado con el front (AIModelSection.tsx).
12
- // Si se actualiza el dropdown del front, actualizar aqui tambien.
13
- const MODELS: Record<string, string[]> = {
14
- openai: [
15
- // GPT-5.4 (flagship actual)
16
- 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano',
17
- // GPT-5.2
18
- 'gpt-5.2',
19
- // GPT-5.1
20
- 'gpt-5.1', 'gpt-5.1-codex', 'gpt-5.1-codex-mini',
21
- // GPT-5
22
- 'gpt-5', 'gpt-5-mini', 'gpt-5-nano',
23
- // GPT-4.1
24
- 'gpt-4.1', 'gpt-4.1-mini', 'gpt-4.1-nano',
25
- // GPT-4o
26
- 'gpt-4o', 'gpt-4o-mini',
27
- // Razonamiento (o-series)
28
- 'o4-mini', 'o3', 'o3-mini', 'o1-2024-12-17',
29
- // Legacy
30
- 'gpt-4-turbo', 'gpt-3.5-turbo',
31
- ],
32
- claude: [
33
- // Mythos-class (flagship)
34
- 'claude-fable-5',
35
- // Claude 4.6
36
- 'claude-opus-4-6', 'claude-sonnet-4-6',
37
- // Claude 4.5
38
- 'claude-opus-4-5-20251101', 'claude-sonnet-4-5-20250929', 'claude-haiku-4-5-20251001',
39
- // Claude 4.x
40
- 'claude-opus-4-1-20250805', 'claude-opus-4-20250514', 'claude-sonnet-4-20250514',
41
- ],
42
- gemini: [
43
- // Gemini 3.1 (flagship actual)
44
- 'gemini-3.1-pro-preview', 'gemini-3.1-flash-lite-preview',
45
- // Gemini 2.5
46
- 'gemini-2.5-pro', 'gemini-2.5-flash', 'gemini-2.5-flash-lite',
47
- // Gemini 2.0
48
- 'gemini-2.0-flash',
49
- ],
50
- };
51
-
52
- const DEFAULT_MODEL: Record<string, string> = {
53
- openai: 'gpt-4o',
54
- claude: 'claude-sonnet-4-6',
55
- gemini: 'gemini-2.5-pro',
56
- };
57
-
58
- export const aiConfigCommand = new Command('ai-config')
59
- .description('Configure the agent AI provider')
60
- .argument('<agentId>', 'Agent ID')
61
- .option('--dev', 'Use development environment', false)
62
- .action(async (agentId: string, options: AgentCommandOptions) => {
63
- try {
64
- const credentials = await getStoredCredentials();
65
- const agent = new Agent({
66
- workspaceId: credentials.workspace,
67
- apiKey: credentials.apiKey,
68
- zone: credentials.zone,
69
- ...(options.dev && { customUrl: "http://localhost:5090" })
70
- });
71
-
72
- const spinner = createSpinner('Loading agent...');
73
- spinner.start();
74
- let agentData: any;
75
- try {
76
- const _res: any = await agent.getAgentById({ id: agentId });
77
- agentData = _res.agent || _res.data || _res;
78
- spinner.stop();
79
- } catch (loadErr) {
80
- spinner.stop();
81
- logger.error(describeAgentLoadError(loadErr, agentId, credentials, { dev: options.dev }));
82
- process.exit(1);
83
- }
84
-
85
- console.log(section('AI Configuration - ' + (agentData.name || agentId)));
86
-
87
- const currentProviders = agentData.aiProviders || [];
88
- if (currentProviders.length > 0 && agentData.customAIConfig) {
89
- console.log(theme.bold('\n Current configuration:'));
90
- currentProviders.forEach((p: any) => {
91
- console.log(kvPair(' Provider', p.provider));
92
- console.log(kvPair(' Model', p.model));
93
- console.log(kvPair(' Temperature', String(p.temperature)));
94
- console.log(kvPair(' Max Tokens', String(p.maxTokens)));
95
- console.log(kvPair(' Default', p.isDefault ? 'Yes' : 'No'));
96
- });
97
- } else {
98
- console.log(theme.muted('\n Using default AI configuration (Plazbot)'));
99
- }
100
-
101
- const { action } = await (inquirer as any).prompt([{
102
- type: 'list',
103
- name: 'action',
104
- message: 'What would you like to do?',
105
- choices: [
106
- { name: 'Configure new provider', value: 'set' },
107
- { name: 'Use default configuration', value: 'reset' },
108
- { name: 'Exit', value: 'exit' },
109
- ],
110
- }]);
111
-
112
- if (action === 'exit') return;
113
-
114
- if (action === 'reset') {
115
- const { id, _id, ...resetConfig } = { ...agentData, customAIConfig: false, aiProviders: [] };
116
- const resetSpinner = createSpinner('Resetting configuration...');
117
- resetSpinner.start();
118
- await agent.updateAgent(agentId, resetConfig);
119
- resetSpinner.succeed('Using default configuration');
120
- return;
121
- }
122
-
123
- // Configurar nuevo proveedor
124
- const ai = await (inquirer as any).prompt([
125
- { type: 'list', name: 'provider', message: 'Provider:', choices: ['openai', 'claude', 'gemini'] },
126
- ]);
127
-
128
- const models = MODELS[ai.provider] || MODELS.openai;
129
-
130
- const config = await (inquirer as any).prompt([
131
- { type: 'list', name: 'model', message: 'Model:', choices: models, default: DEFAULT_MODEL[ai.provider] },
132
- { type: 'password', name: 'apiToken', message: 'API Token:', mask: '*', validate: (v: string) => v.length > 0 || 'Required' },
133
- { type: 'number', name: 'temperature', message: 'Temperature (0-2):', default: 0.7 },
134
- { type: 'number', name: 'maxTokens', message: 'Max tokens (1024-16384):', default: 4096 },
135
- ]);
136
-
137
- const { id: _uid, _id: _oid, ...updatedConfig } = {
138
- ...agentData,
139
- customAIConfig: true,
140
- aiProviders: [{
141
- provider: ai.provider,
142
- model: config.model,
143
- apiToken: config.apiToken,
144
- temperature: config.temperature,
145
- maxTokens: config.maxTokens,
146
- isDefault: true,
147
- }],
148
- };
149
- const updateSpinner = createSpinner('Saving configuration...');
150
- updateSpinner.start();
151
- await agent.updateAgent(agentId, updatedConfig);
152
- updateSpinner.succeed(`Provider configured: ${ai.provider} / ${config.model}`);
153
-
154
- } catch (error) {
155
- const message = error instanceof Error ? error.message : 'Unknown error';
156
- logger.error(message);
157
- process.exit(1);
158
- }
159
- });
160
-
161
- addExamples(aiConfigCommand, [
162
- { description: 'Pick provider/model/API key for the agent interactively',
163
- command: 'plazbot agent ai-config agt_AbcDef123' },
164
- ]);
@@ -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
- ]);