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,30 +1,31 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
4
|
-
import { logger } from '../../utils/logger';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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';
|
|
7
9
|
import crypto from 'crypto';
|
|
8
10
|
import readline from 'readline';
|
|
9
11
|
import chalk from 'chalk';
|
|
10
12
|
|
|
11
13
|
const COMMANDS_HELP = `
|
|
12
|
-
${chalk.bold('
|
|
13
|
-
${chalk.hex('#4CAF50')('/exit')}
|
|
14
|
-
${chalk.hex('#4CAF50')('/clear')}
|
|
15
|
-
${chalk.hex('#4CAF50')('/info')}
|
|
16
|
-
${chalk.hex('#4CAF50')('/sources')}
|
|
17
|
-
${chalk.hex('#4CAF50')('/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
|
|
18
20
|
`;
|
|
19
21
|
|
|
20
22
|
export const chatCommand = new Command('chat')
|
|
21
|
-
.description('
|
|
22
|
-
.
|
|
23
|
-
.option('-s, --session-id <id>', 'ID
|
|
24
|
-
.option('-m, --multiple-answers', '
|
|
25
|
-
.option('--dev', '
|
|
26
|
-
.action(async (options: AgentCommandOptions & {
|
|
27
|
-
agentId: string;
|
|
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 & {
|
|
28
29
|
sessionId?: string;
|
|
29
30
|
multipleAnswers?: boolean;
|
|
30
31
|
}) => {
|
|
@@ -44,12 +45,14 @@ export const chatCommand = new Command('chat')
|
|
|
44
45
|
// Cargar info del agente
|
|
45
46
|
let agentInfo: any = null;
|
|
46
47
|
try {
|
|
47
|
-
process.stdout.write(chalk.gray('
|
|
48
|
-
const _res: any = await agent.getAgentById({ id:
|
|
48
|
+
process.stdout.write(chalk.gray(' Connecting to agent...'));
|
|
49
|
+
const _res: any = await agent.getAgentById({ id: agentId });
|
|
49
50
|
agentInfo = _res.agent || _res.data || _res;
|
|
50
51
|
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
51
|
-
} catch {
|
|
52
|
+
} catch (loadErr) {
|
|
52
53
|
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
54
|
+
logger.error(describeAgentLoadError(loadErr, agentId, credentials, { dev: options.dev }));
|
|
55
|
+
process.exit(1);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
const rl = readline.createInterface({
|
|
@@ -59,27 +62,27 @@ export const chatCommand = new Command('chat')
|
|
|
59
62
|
|
|
60
63
|
// Pantalla de chat
|
|
61
64
|
console.clear();
|
|
62
|
-
const agentName = agentInfo?.name || '
|
|
65
|
+
const agentName = agentInfo?.name || 'Agent';
|
|
63
66
|
const toolCalling = agentInfo?.useToolCalling ? chalk.hex('#4CAF50')(' [Tool Calling]') : '';
|
|
64
67
|
|
|
65
68
|
console.log();
|
|
66
69
|
console.log(chalk.hex('#4CAF50')(' ┌' + '─'.repeat(58) + '┐'));
|
|
67
70
|
console.log(chalk.hex('#4CAF50')(' │') + chalk.bold(` ${agentName}${toolCalling}`).padEnd(68) + chalk.hex('#4CAF50')('│'));
|
|
68
71
|
console.log(chalk.hex('#4CAF50')(' │') + chalk.gray(` Session: ${sessionId.substring(0, 8)}...`).padEnd(68) + chalk.hex('#4CAF50')('│'));
|
|
69
|
-
console.log(chalk.hex('#4CAF50')(' │') + chalk.gray(' /help
|
|
72
|
+
console.log(chalk.hex('#4CAF50')(' │') + chalk.gray(' /help to see commands').padEnd(68) + chalk.hex('#4CAF50')('│'));
|
|
70
73
|
console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(58) + '┘'));
|
|
71
74
|
console.log();
|
|
72
75
|
|
|
73
76
|
// Saludo del agente
|
|
74
77
|
if (agentInfo?.instructions?.greeting) {
|
|
75
|
-
const timestamp = new Date().toLocaleTimeString('
|
|
78
|
+
const timestamp = new Date().toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
|
|
76
79
|
console.log(chalk.hex('#4CAF50')(` ${agentName}`) + chalk.gray(` ${timestamp}`));
|
|
77
80
|
console.log(chalk.white(` ${agentInfo.instructions.greeting}`));
|
|
78
81
|
console.log();
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
const askQuestion = () => {
|
|
82
|
-
rl.question(chalk.hex('#2196F3')('
|
|
85
|
+
rl.question(chalk.hex('#2196F3')(' You > '), async (question) => {
|
|
83
86
|
if (!question.trim()) {
|
|
84
87
|
askQuestion();
|
|
85
88
|
return;
|
|
@@ -87,7 +90,7 @@ export const chatCommand = new Command('chat')
|
|
|
87
90
|
|
|
88
91
|
// Comandos especiales
|
|
89
92
|
if (question.toLowerCase() === '/exit') {
|
|
90
|
-
console.log(chalk.gray('\n
|
|
93
|
+
console.log(chalk.gray('\n Session ended.\n'));
|
|
91
94
|
rl.close();
|
|
92
95
|
return;
|
|
93
96
|
}
|
|
@@ -105,11 +108,11 @@ export const chatCommand = new Command('chat')
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
if (question.toLowerCase() === '/info') {
|
|
108
|
-
console.log(section('
|
|
109
|
-
logger.label('Agent ID',
|
|
111
|
+
console.log(section('Session information'));
|
|
112
|
+
logger.label('Agent ID', agentId);
|
|
110
113
|
logger.label('Session ID', sessionId);
|
|
111
|
-
logger.label('
|
|
112
|
-
logger.label('Tool Calling', agentInfo?.useToolCalling ? '
|
|
114
|
+
logger.label('Agent', agentName);
|
|
115
|
+
logger.label('Tool Calling', agentInfo?.useToolCalling ? 'Enabled' : 'Disabled');
|
|
113
116
|
logger.label('AI Provider', agentInfo?.customAIConfig ? (agentInfo.aiProviders?.[0]?.provider || 'Custom') : 'Default');
|
|
114
117
|
console.log();
|
|
115
118
|
askQuestion();
|
|
@@ -118,23 +121,23 @@ export const chatCommand = new Command('chat')
|
|
|
118
121
|
|
|
119
122
|
if (question.toLowerCase() === '/sources') {
|
|
120
123
|
showSources = !showSources;
|
|
121
|
-
console.log(chalk.gray(`
|
|
124
|
+
console.log(chalk.gray(` Sources: ${showSources ? 'on' : 'off'}`));
|
|
122
125
|
console.log();
|
|
123
126
|
askQuestion();
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
try {
|
|
128
|
-
process.stdout.write(chalk.gray(' ...
|
|
131
|
+
process.stdout.write(chalk.gray(' ...thinking\n'));
|
|
129
132
|
|
|
130
133
|
const response = await agent.onMessage({
|
|
131
|
-
agentId:
|
|
134
|
+
agentId: agentId,
|
|
132
135
|
question,
|
|
133
136
|
sessionId,
|
|
134
137
|
multipleAnswers: options.multipleAnswers
|
|
135
138
|
}) as AgentResponse & { actionsExecuted?: any[] };
|
|
136
139
|
|
|
137
|
-
const timestamp = new Date().toLocaleTimeString('
|
|
140
|
+
const timestamp = new Date().toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
|
|
138
141
|
|
|
139
142
|
// Mostrar tool calls si hay
|
|
140
143
|
if (response.actionsExecuted && response.actionsExecuted.length > 0) {
|
|
@@ -154,9 +157,9 @@ export const chatCommand = new Command('chat')
|
|
|
154
157
|
|
|
155
158
|
// Fuentes
|
|
156
159
|
if (showSources && response.sources && response.sources.length > 0) {
|
|
157
|
-
console.log(chalk.gray('
|
|
160
|
+
console.log(chalk.gray(' Sources:'));
|
|
158
161
|
response.sources.forEach((source: AgentSource) => {
|
|
159
|
-
console.log(chalk.gray(` - ${source.title || '
|
|
162
|
+
console.log(chalk.gray(` - ${source.title || 'Untitled'}`));
|
|
160
163
|
if (source.url) console.log(chalk.gray(` ${source.url}`));
|
|
161
164
|
});
|
|
162
165
|
console.log();
|
|
@@ -164,7 +167,7 @@ export const chatCommand = new Command('chat')
|
|
|
164
167
|
|
|
165
168
|
askQuestion();
|
|
166
169
|
} catch (error) {
|
|
167
|
-
const message = error instanceof Error ? error.message : '
|
|
170
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
168
171
|
console.log(chalk.hex('#EF5350')(`\n ✖ Error: ${message}\n`));
|
|
169
172
|
askQuestion();
|
|
170
173
|
}
|
|
@@ -174,12 +177,21 @@ export const chatCommand = new Command('chat')
|
|
|
174
177
|
askQuestion();
|
|
175
178
|
|
|
176
179
|
} catch (error) {
|
|
177
|
-
const message = error instanceof Error ? error.message : '
|
|
180
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
178
181
|
logger.error(message);
|
|
179
182
|
process.exit(1);
|
|
180
183
|
}
|
|
181
184
|
});
|
|
182
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
|
+
|
|
183
195
|
function formatResponse(text: string): string {
|
|
184
196
|
if (!text) return '';
|
|
185
197
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
4
|
-
import { logger } from '../../utils/logger';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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';
|
|
7
8
|
|
|
8
9
|
export const copyCommand = new Command('copy')
|
|
9
|
-
.description('
|
|
10
|
-
.argument('<agentId>', 'ID
|
|
11
|
-
.option('--dev', '
|
|
10
|
+
.description('Clone an existing agent')
|
|
11
|
+
.argument('<agentId>', 'Agent ID to clone')
|
|
12
|
+
.option('--dev', 'Use development environment', false)
|
|
12
13
|
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
13
14
|
try {
|
|
14
15
|
const credentials = await getStoredCredentials();
|
|
@@ -19,22 +20,27 @@ export const copyCommand = new Command('copy')
|
|
|
19
20
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
const spinner = createSpinner('
|
|
23
|
+
const spinner = createSpinner('Cloning agent...');
|
|
23
24
|
spinner.start();
|
|
24
25
|
|
|
25
26
|
const result = await (agent as any).copyAgent({ id: agentId });
|
|
26
27
|
|
|
27
|
-
spinner.succeed('
|
|
28
|
+
spinner.succeed('Agent cloned successfully');
|
|
28
29
|
|
|
29
|
-
logger.title('
|
|
30
|
+
logger.title('Cloned agent');
|
|
30
31
|
if (result?.agentId || result?.id) {
|
|
31
|
-
logger.label('
|
|
32
|
+
logger.label('New ID', result.agentId || result.id);
|
|
32
33
|
}
|
|
33
|
-
logger.dim('\
|
|
34
|
+
logger.dim('\nThe cloned agent has the widget disabled by default.');
|
|
34
35
|
|
|
35
36
|
} catch (error) {
|
|
36
|
-
const message = error instanceof Error ? error.message : '
|
|
37
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
37
38
|
logger.error(message);
|
|
38
39
|
process.exit(1);
|
|
39
40
|
}
|
|
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,16 +1,17 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
4
|
-
import { logger } from '../../utils/logger';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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';
|
|
8
9
|
import fs from 'fs/promises';
|
|
9
10
|
|
|
10
11
|
export const createCommand = new Command('create')
|
|
11
|
-
.description('
|
|
12
|
-
.argument('[configPath]', '
|
|
13
|
-
.option('--dev', '
|
|
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)
|
|
14
15
|
.action(async (configPath: string | undefined, options: AgentCommandOptions) => {
|
|
15
16
|
try {
|
|
16
17
|
const credentials = await getStoredCredentials();
|
|
@@ -30,10 +31,10 @@ export const createCommand = new Command('create')
|
|
|
30
31
|
const fileContent = await fs.readFile(configPath, 'utf-8');
|
|
31
32
|
agentConfig = JSON.parse(fileContent);
|
|
32
33
|
} catch (error) {
|
|
33
|
-
const errorMessage = error instanceof Error ? error.message : '
|
|
34
|
-
throw new Error(`
|
|
34
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
35
|
+
throw new Error(`Failed to read config file: ${errorMessage}`);
|
|
35
36
|
}
|
|
36
|
-
logger.title('
|
|
37
|
+
logger.title('Creating agent from file');
|
|
37
38
|
logger.json(agentConfig);
|
|
38
39
|
} else {
|
|
39
40
|
// Modo wizard interactivo
|
|
@@ -43,51 +44,60 @@ export const createCommand = new Command('create')
|
|
|
43
44
|
const { confirm } = await inquirer.default.prompt([{
|
|
44
45
|
type: 'confirm',
|
|
45
46
|
name: 'confirm',
|
|
46
|
-
message: '
|
|
47
|
+
message: 'Create the agent with this configuration?',
|
|
47
48
|
default: true,
|
|
48
49
|
}]);
|
|
49
50
|
|
|
50
51
|
if (!confirm) {
|
|
51
|
-
logger.warning('
|
|
52
|
+
logger.warning('Creation cancelled');
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
const spinner = createSpinner('
|
|
57
|
+
const spinner = createSpinner('Creating agent...');
|
|
57
58
|
spinner.start();
|
|
58
59
|
|
|
59
60
|
const result = await agent.addAgent(agentConfig);
|
|
60
61
|
|
|
61
|
-
spinner.succeed('
|
|
62
|
+
spinner.succeed('Agent created successfully');
|
|
62
63
|
|
|
63
|
-
logger.title('
|
|
64
|
+
logger.title('Agent details');
|
|
64
65
|
if (result.agentId) {
|
|
65
66
|
logger.label('ID', result.agentId);
|
|
66
67
|
}
|
|
67
68
|
if (agentConfig.name) {
|
|
68
|
-
logger.label('
|
|
69
|
+
logger.label('Name', agentConfig.name);
|
|
69
70
|
}
|
|
70
|
-
logger.label('Tool Calling', agentConfig.useToolCalling ? '
|
|
71
|
+
logger.label('Tool Calling', agentConfig.useToolCalling ? 'Enabled' : 'Disabled');
|
|
71
72
|
|
|
72
73
|
if (agentConfig.channels && agentConfig.channels.length > 0) {
|
|
73
74
|
agentConfig.channels.forEach((ch: any) => {
|
|
74
|
-
logger.label(`
|
|
75
|
+
logger.label(`Channel (${ch.channel})`, ch.key);
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
console.log();
|
|
79
|
-
logger.dim('
|
|
80
|
+
logger.dim('Next step: plazbot agent chat -a ' + (result.agentId || '<agentId>'));
|
|
80
81
|
console.log();
|
|
81
82
|
|
|
82
83
|
if (options.dev) {
|
|
83
|
-
logger.warning('
|
|
84
|
+
logger.warning('Environment: development');
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
process.exit(0);
|
|
87
88
|
|
|
88
89
|
} catch (error) {
|
|
89
|
-
const message = error instanceof Error ? error.message : '
|
|
90
|
+
const message = error instanceof Error ? error.message : 'Unknown error while creating the agent';
|
|
90
91
|
logger.error(message);
|
|
91
92
|
process.exit(1);
|
|
92
93
|
}
|
|
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,14 +1,15 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
4
|
-
import { logger } from '../../utils/logger';
|
|
5
|
-
import {
|
|
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';
|
|
6
7
|
import readline from 'readline';
|
|
7
8
|
|
|
8
9
|
export const deleteCommand = new Command('delete')
|
|
9
|
-
.description('
|
|
10
|
-
.argument('<agentId>', 'ID
|
|
11
|
-
.option('--dev', '
|
|
10
|
+
.description('Delete an existing agent')
|
|
11
|
+
.argument('<agentId>', 'Agent ID to delete')
|
|
12
|
+
.option('--dev', 'Use development environment', false)
|
|
12
13
|
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
13
14
|
try {
|
|
14
15
|
// Obtener credenciales guardadas
|
|
@@ -25,11 +26,11 @@ export const deleteCommand = new Command('delete')
|
|
|
25
26
|
const response: any = await agent.getAgentById({ id: agentId });
|
|
26
27
|
const agentDetails = response.agent || response.data || response;
|
|
27
28
|
|
|
28
|
-
logger.warning('\
|
|
29
|
+
logger.warning('\nYou are about to delete the following agent:');
|
|
29
30
|
logger.divider();
|
|
30
31
|
logger.info(`ID: ${agentDetails.id || agentId}`);
|
|
31
|
-
logger.info(`
|
|
32
|
-
logger.info(`
|
|
32
|
+
logger.info(`Name: ${agentDetails.name || '—'}`);
|
|
33
|
+
logger.info(`Description: ${agentDetails.description || '—'}`);
|
|
33
34
|
logger.divider();
|
|
34
35
|
|
|
35
36
|
// Crear interfaz para confirmación
|
|
@@ -39,27 +40,32 @@ export const deleteCommand = new Command('delete')
|
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
// Preguntar por confirmación
|
|
42
|
-
rl.question('\
|
|
43
|
+
rl.question('\nAre you sure you want to delete this agent? (y/N): ', async (answer) => {
|
|
43
44
|
if (answer.toLowerCase() === 'y') {
|
|
44
45
|
await agent.deleteAgent({
|
|
45
46
|
id: agentId
|
|
46
47
|
});
|
|
47
|
-
|
|
48
|
-
logger.success('
|
|
49
|
-
|
|
48
|
+
|
|
49
|
+
logger.success('Agent deleted successfully');
|
|
50
|
+
|
|
50
51
|
if (options.dev) {
|
|
51
|
-
logger.warning('
|
|
52
|
+
logger.warning('Environment: development');
|
|
52
53
|
}
|
|
53
54
|
} else {
|
|
54
|
-
logger.error('
|
|
55
|
+
logger.error('Operation cancelled');
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
|
|
57
58
|
rl.close();
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
} catch (error) {
|
|
61
|
-
const message = error instanceof Error ? error.message : '
|
|
62
|
+
const message = error instanceof Error ? error.message : 'Unknown error while deleting the agent';
|
|
62
63
|
logger.error(message);
|
|
63
64
|
process.exit(1);
|
|
64
65
|
}
|
|
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,14 +1,15 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
4
|
-
import { logger } from '../../utils/logger';
|
|
5
|
-
import {
|
|
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';
|
|
6
7
|
|
|
7
8
|
export const enableCommand = new Command('enable-widget')
|
|
8
|
-
.description('
|
|
9
|
-
.argument('<agentId>', 'ID
|
|
10
|
-
.option('-d, --disable', '
|
|
11
|
-
.option('--dev', '
|
|
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)
|
|
12
13
|
.action(async (agentId: string, options: EnableWidgetOptions) => {
|
|
13
14
|
try {
|
|
14
15
|
// Obtener credenciales guardadas
|
|
@@ -25,35 +26,42 @@ export const enableCommand = new Command('enable-widget')
|
|
|
25
26
|
const _res: any = await agent.getAgentById({ id: agentId });
|
|
26
27
|
const agentDetails = _res.agent || _res.data || _res;
|
|
27
28
|
|
|
28
|
-
logger.title('
|
|
29
|
-
logger.label('
|
|
29
|
+
logger.title('Current widget status');
|
|
30
|
+
logger.label('Agent', agentDetails.name);
|
|
30
31
|
|
|
31
32
|
// Cambiar estado
|
|
32
33
|
const newState = !options.disable; // Si --disable está presente, newState será false
|
|
33
|
-
const result = await agent.enableWidget({
|
|
34
|
-
id: agentId,
|
|
35
|
-
enable: newState
|
|
34
|
+
const result = await agent.enableWidget({
|
|
35
|
+
id: agentId,
|
|
36
|
+
enable: newState
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
logger.success(`Widget ${newState ? '
|
|
39
|
-
|
|
40
|
-
logger.title('
|
|
41
|
-
logger.label('
|
|
42
|
-
logger.label('
|
|
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);
|
|
43
44
|
|
|
44
45
|
if (newState && result.script) {
|
|
45
|
-
logger.title('
|
|
46
|
-
logger.dim('
|
|
46
|
+
logger.title('Installation instructions');
|
|
47
|
+
logger.dim('Place this script under the <HEAD> tag of your website:');
|
|
47
48
|
logger.info('\n' + result.script);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
|
|
50
51
|
if (options.dev) {
|
|
51
|
-
logger.warning('
|
|
52
|
+
logger.warning('Environment: development');
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
} catch (error) {
|
|
55
|
-
const message = error instanceof Error ? error.message : '
|
|
56
|
+
const message = error instanceof Error ? error.message : 'Unknown error while updating the widget';
|
|
56
57
|
logger.error(message);
|
|
57
58
|
process.exit(1);
|
|
58
59
|
}
|
|
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
|
+
]);
|