plazbot-cli 0.2.26 → 0.3.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.
- 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 +32 -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 +21 -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 +32 -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,8 +1,9 @@
|
|
|
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 { theme } from '../../utils/ui.js';
|
|
6
7
|
import chalk from 'chalk';
|
|
7
8
|
import readline from 'readline';
|
|
8
9
|
import { HubConnectionBuilder, HttpTransportType, HubConnectionState } from '@microsoft/signalr';
|
|
@@ -48,7 +49,7 @@ function getBaseUrl(zone: string, dev: boolean): string {
|
|
|
48
49
|
function formatTimestamp(ts: string): string {
|
|
49
50
|
try {
|
|
50
51
|
const d = new Date(ts);
|
|
51
|
-
return d.toLocaleTimeString('
|
|
52
|
+
return d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
52
53
|
} catch {
|
|
53
54
|
return ts.substring(11, 19);
|
|
54
55
|
}
|
|
@@ -83,7 +84,7 @@ function renderLogLine(
|
|
|
83
84
|
|
|
84
85
|
// Separador de sesion
|
|
85
86
|
if (lastSessionId && log.session_id && log.session_id !== lastSessionId) {
|
|
86
|
-
lines.push(dimFn(' ' + '─'.repeat(16) + '
|
|
87
|
+
lines.push(dimFn(' ' + '─'.repeat(16) + ' new session ' + '─'.repeat(16)));
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
// Linea principal
|
|
@@ -100,7 +101,7 @@ function renderLogLine(
|
|
|
100
101
|
|
|
101
102
|
// Linea de contacto para mensajes
|
|
102
103
|
if (log.contact_name && (log.event_type === 'msg_in' || log.event_type === 'msg_out')) {
|
|
103
|
-
lines.push(dimFn(' |
|
|
104
|
+
lines.push(dimFn(' | contact: ') + dimFn(log.contact_name));
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
return lines.join('\n');
|
|
@@ -112,20 +113,20 @@ function printHeader(agentName: string) {
|
|
|
112
113
|
console.log(
|
|
113
114
|
chalk.hex('#4CAF50')(' │') +
|
|
114
115
|
chalk.bold(` Monitor`) +
|
|
115
|
-
chalk.hex('#4ade80')(' ●
|
|
116
|
-
' '.repeat(
|
|
116
|
+
chalk.hex('#4ade80')(' ● Live') +
|
|
117
|
+
' '.repeat(42) +
|
|
117
118
|
chalk.hex('#4CAF50')('│')
|
|
118
119
|
);
|
|
119
120
|
console.log(
|
|
120
121
|
chalk.hex('#4CAF50')(' │') +
|
|
121
|
-
chalk.gray(`
|
|
122
|
-
' '.repeat(Math.max(0,
|
|
122
|
+
chalk.gray(` Agent: ${truncate(agentName, 44)}`) +
|
|
123
|
+
' '.repeat(Math.max(0, 50 - agentName.length)) +
|
|
123
124
|
chalk.hex('#4CAF50')('│')
|
|
124
125
|
);
|
|
125
126
|
console.log(
|
|
126
127
|
chalk.hex('#4CAF50')(' │') +
|
|
127
|
-
chalk.gray(' Ctrl+C
|
|
128
|
-
' '.repeat(
|
|
128
|
+
chalk.gray(' Ctrl+C exit | /filter <type> | /clear | /help') +
|
|
129
|
+
' '.repeat(13) +
|
|
129
130
|
chalk.hex('#4CAF50')('│')
|
|
130
131
|
);
|
|
131
132
|
console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(62) + '┘'));
|
|
@@ -133,31 +134,30 @@ function printHeader(agentName: string) {
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
const COMMANDS_HELP = `
|
|
136
|
-
${chalk.bold('
|
|
137
|
-
${chalk.hex('#4CAF50')('/filter <
|
|
138
|
-
${chalk.hex('#4CAF50')('/filter clear')}
|
|
139
|
-
${chalk.hex('#4CAF50')('/filters')}
|
|
140
|
-
${chalk.hex('#4CAF50')('/clear')}
|
|
141
|
-
${chalk.hex('#4CAF50')('/json')} Toggle
|
|
142
|
-
${chalk.hex('#4CAF50')('/help')}
|
|
143
|
-
|
|
144
|
-
${chalk.bold('
|
|
137
|
+
${chalk.bold('Available commands:')}
|
|
138
|
+
${chalk.hex('#4CAF50')('/filter <type>')} Toggle filter by type (e.g. msg_in, error, tool_call)
|
|
139
|
+
${chalk.hex('#4CAF50')('/filter clear')} Remove all filters
|
|
140
|
+
${chalk.hex('#4CAF50')('/filters')} Show active filters
|
|
141
|
+
${chalk.hex('#4CAF50')('/clear')} Clear screen
|
|
142
|
+
${chalk.hex('#4CAF50')('/json')} Toggle expanded JSON mode
|
|
143
|
+
${chalk.hex('#4CAF50')('/help')} Show these commands
|
|
144
|
+
|
|
145
|
+
${chalk.bold('Event types:')}
|
|
145
146
|
${Object.entries(EVENT_COLORS).map(([key, val]) =>
|
|
146
147
|
` ${chalk.hex(val.color)('●')} ${key}`
|
|
147
148
|
).join('\n')}
|
|
148
149
|
`;
|
|
149
150
|
|
|
150
151
|
export const monitorCommand = new Command('monitor')
|
|
151
|
-
.description('
|
|
152
|
-
.
|
|
153
|
-
.option('-f, --filter <types>', '
|
|
154
|
-
.option('--no-session', '
|
|
155
|
-
.option('--json', '
|
|
156
|
-
.option('-w, --workspace <id>', 'Workspace ID (
|
|
157
|
-
.option('-z, --zone <zone>', '
|
|
158
|
-
.option('--dev', '
|
|
159
|
-
.action(async (options: {
|
|
160
|
-
agentId: string;
|
|
152
|
+
.description('Real-time agent monitor (logs via SignalR)')
|
|
153
|
+
.argument('<agentId>', 'Agent ID')
|
|
154
|
+
.option('-f, --filter <types>', 'Filter by comma-separated types (e.g. msg_in,msg_out)')
|
|
155
|
+
.option('--no-session', 'Hide session ID')
|
|
156
|
+
.option('--json', 'Raw JSON mode (for piping)', false)
|
|
157
|
+
.option('-w, --workspace <id>', 'Workspace ID (overrides local config)')
|
|
158
|
+
.option('-z, --zone <zone>', 'Zone LA or EU (overrides local config)')
|
|
159
|
+
.option('--dev', 'Use development environment', false)
|
|
160
|
+
.action(async (agentId: string, options: {
|
|
161
161
|
filter?: string;
|
|
162
162
|
session: boolean;
|
|
163
163
|
json: boolean;
|
|
@@ -173,7 +173,7 @@ export const monitorCommand = new Command('monitor')
|
|
|
173
173
|
const baseUrl = getBaseUrl(effectiveZone, options.dev);
|
|
174
174
|
|
|
175
175
|
if (options.workspace || options.zone) {
|
|
176
|
-
console.log(chalk.hex('#FFA726')(`\n
|
|
176
|
+
console.log(chalk.hex('#FFA726')(`\n Support mode: workspace=${effectiveWorkspace} zone=${effectiveZone}`));
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// Filtros iniciales
|
|
@@ -184,16 +184,16 @@ export const monitorCommand = new Command('monitor')
|
|
|
184
184
|
let lastSessionId = '';
|
|
185
185
|
|
|
186
186
|
// Cargar info del agente
|
|
187
|
-
let agentName = '
|
|
187
|
+
let agentName = 'Agent';
|
|
188
188
|
try {
|
|
189
|
-
process.stdout.write(chalk.gray('
|
|
189
|
+
process.stdout.write(chalk.gray(' Connecting to agent...'));
|
|
190
190
|
const agent = new Agent({
|
|
191
191
|
workspaceId: effectiveWorkspace,
|
|
192
192
|
apiKey: credentials.apiKey,
|
|
193
193
|
zone: effectiveZone,
|
|
194
194
|
...(options.dev && { customUrl: 'http://localhost:5090' }),
|
|
195
195
|
});
|
|
196
|
-
const _res: any = await agent.getAgentById({ id:
|
|
196
|
+
const _res: any = await agent.getAgentById({ id: agentId });
|
|
197
197
|
const info = _res.agent || _res.data || _res;
|
|
198
198
|
if (info?.name) agentName = info.name;
|
|
199
199
|
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
@@ -234,33 +234,33 @@ export const monitorCommand = new Command('monitor')
|
|
|
234
234
|
// Eventos de conexion
|
|
235
235
|
connection.onreconnecting(() => {
|
|
236
236
|
if (!jsonMode) {
|
|
237
|
-
console.log(chalk.hex('#FFA726')(' ⟳
|
|
237
|
+
console.log(chalk.hex('#FFA726')(' ⟳ Reconnecting...'));
|
|
238
238
|
}
|
|
239
239
|
});
|
|
240
240
|
|
|
241
241
|
connection.onreconnected(() => {
|
|
242
242
|
if (!jsonMode) {
|
|
243
|
-
console.log(chalk.hex('#4ade80')(' ●
|
|
243
|
+
console.log(chalk.hex('#4ade80')(' ● Reconnected'));
|
|
244
244
|
}
|
|
245
|
-
connection.invoke('JoinAgentMonitor',
|
|
245
|
+
connection.invoke('JoinAgentMonitor', agentId).catch(() => {});
|
|
246
246
|
});
|
|
247
247
|
|
|
248
248
|
connection.onclose(() => {
|
|
249
249
|
if (!jsonMode) {
|
|
250
|
-
console.log(chalk.hex('#ef4444')(' ●
|
|
250
|
+
console.log(chalk.hex('#ef4444')(' ● Disconnected'));
|
|
251
251
|
}
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
// Iniciar conexion
|
|
255
255
|
try {
|
|
256
256
|
await connection.start();
|
|
257
|
-
await connection.invoke('JoinAgentMonitor',
|
|
257
|
+
await connection.invoke('JoinAgentMonitor', agentId);
|
|
258
258
|
if (!jsonMode) {
|
|
259
|
-
console.log(chalk.hex('#4ade80')(' ●
|
|
259
|
+
console.log(chalk.hex('#4ade80')(' ● Connected to real-time monitor'));
|
|
260
260
|
console.log();
|
|
261
261
|
}
|
|
262
262
|
} catch (err) {
|
|
263
|
-
logger.error(`
|
|
263
|
+
logger.error(`Could not connect to monitor: ${err instanceof Error ? err.message : err}`);
|
|
264
264
|
process.exit(1);
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -288,15 +288,15 @@ export const monitorCommand = new Command('monitor')
|
|
|
288
288
|
|
|
289
289
|
if (cmd === '/json') {
|
|
290
290
|
jsonMode = !jsonMode;
|
|
291
|
-
console.log(chalk.gray(`
|
|
291
|
+
console.log(chalk.gray(` JSON mode: ${jsonMode ? 'enabled' : 'disabled'}`));
|
|
292
292
|
return;
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
if (cmd === '/filters') {
|
|
296
296
|
if (activeFilters.size === 0) {
|
|
297
|
-
console.log(chalk.gray('
|
|
297
|
+
console.log(chalk.gray(' No active filters (showing all)'));
|
|
298
298
|
} else {
|
|
299
|
-
console.log(chalk.gray('
|
|
299
|
+
console.log(chalk.gray(' Active filters: ') + chalk.white([...activeFilters].join(', ')));
|
|
300
300
|
}
|
|
301
301
|
return;
|
|
302
302
|
}
|
|
@@ -304,30 +304,30 @@ export const monitorCommand = new Command('monitor')
|
|
|
304
304
|
if (cmd.startsWith('/filter ')) {
|
|
305
305
|
const filterType = cmd.substring(8).trim();
|
|
306
306
|
if (!filterType) {
|
|
307
|
-
console.log(chalk.gray('
|
|
307
|
+
console.log(chalk.gray(' Usage: /filter <type> | /filter clear'));
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
310
|
if (filterType === 'clear') {
|
|
311
311
|
activeFilters.clear();
|
|
312
|
-
console.log(chalk.gray('
|
|
312
|
+
console.log(chalk.gray(' All filters cleared (showing all)'));
|
|
313
313
|
return;
|
|
314
314
|
}
|
|
315
315
|
if (activeFilters.has(filterType)) {
|
|
316
316
|
activeFilters.delete(filterType);
|
|
317
|
-
console.log(chalk.gray(`
|
|
317
|
+
console.log(chalk.gray(` Filter removed: ${filterType}`));
|
|
318
318
|
} else {
|
|
319
319
|
activeFilters.add(filterType);
|
|
320
320
|
const config = EVENT_COLORS[filterType];
|
|
321
321
|
if (config) {
|
|
322
|
-
console.log(chalk.hex(config.color)(` ●
|
|
322
|
+
console.log(chalk.hex(config.color)(` ● Filter added: ${filterType}`));
|
|
323
323
|
} else {
|
|
324
|
-
console.log(chalk.gray(`
|
|
324
|
+
console.log(chalk.gray(` Filter added: ${filterType} (unknown type)`));
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
if (activeFilters.size > 0) {
|
|
328
|
-
console.log(chalk.gray('
|
|
328
|
+
console.log(chalk.gray(' Active: ') + chalk.white([...activeFilters].join(', ')));
|
|
329
329
|
} else {
|
|
330
|
-
console.log(chalk.gray('
|
|
330
|
+
console.log(chalk.gray(' No filters (showing all)'));
|
|
331
331
|
}
|
|
332
332
|
return;
|
|
333
333
|
}
|
|
@@ -336,11 +336,11 @@ export const monitorCommand = new Command('monitor')
|
|
|
336
336
|
// Cierre limpio
|
|
337
337
|
const cleanup = async () => {
|
|
338
338
|
if (!jsonMode) {
|
|
339
|
-
console.log(chalk.gray('\n
|
|
339
|
+
console.log(chalk.gray('\n Closing monitor...'));
|
|
340
340
|
}
|
|
341
341
|
try {
|
|
342
342
|
if (connection.state === HubConnectionState.Connected) {
|
|
343
|
-
await connection.invoke('LeaveAgentMonitor',
|
|
343
|
+
await connection.invoke('LeaveAgentMonitor', agentId);
|
|
344
344
|
}
|
|
345
345
|
await connection.stop();
|
|
346
346
|
} catch {
|
|
@@ -348,7 +348,7 @@ export const monitorCommand = new Command('monitor')
|
|
|
348
348
|
}
|
|
349
349
|
rl.close();
|
|
350
350
|
if (!jsonMode) {
|
|
351
|
-
console.log(chalk.gray(' Monitor
|
|
351
|
+
console.log(chalk.gray(' Monitor closed.\n'));
|
|
352
352
|
}
|
|
353
353
|
process.exit(0);
|
|
354
354
|
};
|
|
@@ -357,8 +357,19 @@ export const monitorCommand = new Command('monitor')
|
|
|
357
357
|
process.on('SIGTERM', cleanup);
|
|
358
358
|
|
|
359
359
|
} catch (error) {
|
|
360
|
-
const message = error instanceof Error ? error.message : '
|
|
360
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
361
361
|
logger.error(message);
|
|
362
362
|
process.exit(1);
|
|
363
363
|
}
|
|
364
364
|
});
|
|
365
|
+
|
|
366
|
+
addExamples(monitorCommand, [
|
|
367
|
+
{ description: 'Stream every event of an agent in real time',
|
|
368
|
+
command: 'plazbot agent monitor agt_AbcDef123' },
|
|
369
|
+
{ description: 'Only show inbound/outbound messages and errors',
|
|
370
|
+
command: 'plazbot agent monitor agt_AbcDef123 -f msg_in,msg_out,error' },
|
|
371
|
+
{ description: 'Emit raw JSON (one event per line) for piping to jq',
|
|
372
|
+
command: 'plazbot agent monitor agt_AbcDef123 --json' },
|
|
373
|
+
{ description: 'Tail an agent from a different workspace (support mode)',
|
|
374
|
+
command: 'plazbot agent monitor agt_AbcDef123 -w wok_Other123 -z LA' },
|
|
375
|
+
]);
|
|
@@ -1,19 +1,19 @@
|
|
|
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, AgentResponse, AgentSource } from '../../types/agent.js';
|
|
6
7
|
import crypto from 'crypto';
|
|
7
8
|
|
|
8
9
|
export const messageCommand = new Command('message')
|
|
9
|
-
.description('
|
|
10
|
-
.
|
|
11
|
-
.requiredOption('-q, --question <text>', '
|
|
12
|
-
.option('-s, --session-id <id>', 'ID
|
|
13
|
-
.option('-m, --multiple-answers', '
|
|
14
|
-
.option('--dev', '
|
|
15
|
-
.action(async (options: AgentCommandOptions & {
|
|
16
|
-
agentId: string;
|
|
10
|
+
.description('Send a message to an agent and get its response')
|
|
11
|
+
.argument('<agentId>', 'Agent ID')
|
|
12
|
+
.requiredOption('-q, --question <text>', 'Message or question for the agent')
|
|
13
|
+
.option('-s, --session-id <id>', 'Session ID (optional)')
|
|
14
|
+
.option('-m, --multiple-answers', 'Allow multiple answers', false)
|
|
15
|
+
.option('--dev', 'Use development environment', false)
|
|
16
|
+
.action(async (agentId: string, options: AgentCommandOptions & {
|
|
17
17
|
question: string;
|
|
18
18
|
sessionId?: string;
|
|
19
19
|
multipleAnswers?: boolean;
|
|
@@ -21,7 +21,7 @@ export const messageCommand = new Command('message')
|
|
|
21
21
|
try {
|
|
22
22
|
// Obtener credenciales guardadas
|
|
23
23
|
const credentials = await getStoredCredentials();
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
const agent = new Agent({
|
|
26
26
|
workspaceId: credentials.workspace,
|
|
27
27
|
apiKey: credentials.apiKey,
|
|
@@ -32,42 +32,51 @@ export const messageCommand = new Command('message')
|
|
|
32
32
|
// Generar un sessionId si no se proporcionó uno
|
|
33
33
|
const sessionId = options.sessionId || crypto.randomUUID();
|
|
34
34
|
|
|
35
|
-
logger.title('
|
|
36
|
-
logger.label('ID
|
|
37
|
-
logger.label('
|
|
38
|
-
logger.label('ID
|
|
35
|
+
logger.title('Sending message to agent');
|
|
36
|
+
logger.label('Agent ID', agentId);
|
|
37
|
+
logger.label('Question', options.question);
|
|
38
|
+
logger.label('Session ID', sessionId);
|
|
39
39
|
if (options.multipleAnswers) {
|
|
40
|
-
logger.info('
|
|
40
|
+
logger.info('Mode: Multiple answers');
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
const response = await agent.onMessage({
|
|
44
|
-
agentId:
|
|
44
|
+
agentId: agentId,
|
|
45
45
|
question: options.question,
|
|
46
46
|
sessionId,
|
|
47
47
|
multipleAnswers: options.multipleAnswers
|
|
48
48
|
}) as AgentResponse;
|
|
49
49
|
|
|
50
|
-
logger.title('
|
|
50
|
+
logger.title('Agent Response');
|
|
51
51
|
console.log(response.answer);
|
|
52
52
|
|
|
53
53
|
if (response.sources && response.sources.length > 0) {
|
|
54
|
-
logger.title('
|
|
54
|
+
logger.title('Sources');
|
|
55
55
|
response.sources.forEach((source: AgentSource) => {
|
|
56
|
-
logger.label('
|
|
56
|
+
logger.label('Title', source.title || 'Untitled');
|
|
57
57
|
if (source.url) logger.label('URL', source.url);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
logger.title('
|
|
61
|
+
logger.title('Session');
|
|
62
62
|
logger.label('ID', sessionId);
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
if (options.dev) {
|
|
65
|
-
logger.warning('\
|
|
65
|
+
logger.warning('\nEnvironment: development');
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
} catch (error) {
|
|
69
|
-
const message = error instanceof Error ? error.message : '
|
|
69
|
+
const message = error instanceof Error ? error.message : 'Unknown error while sending the message';
|
|
70
70
|
logger.error(message);
|
|
71
71
|
process.exit(1);
|
|
72
72
|
}
|
|
73
|
-
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
addExamples(messageCommand, [
|
|
76
|
+
{ description: 'Send a one-shot question to an agent',
|
|
77
|
+
command: 'plazbot agent message agt_AbcDef123 -q "What plans do you offer?"' },
|
|
78
|
+
{ description: 'Continue an existing session',
|
|
79
|
+
command: 'plazbot agent message agt_AbcDef123 -q "And the price?" -s sess_AbcDef123' },
|
|
80
|
+
{ description: 'Allow multiple answers per turn',
|
|
81
|
+
command: 'plazbot agent message agt_AbcDef123 -q "Tell me everything" -m' },
|
|
82
|
+
]);
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
3
|
import inquirer from 'inquirer';
|
|
4
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
5
|
-
import { logger } from '../../utils/logger';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { getStoredCredentials } from '../../utils/credentials.js';
|
|
5
|
+
import { logger } from '../../utils/logger.js';
|
|
6
|
+
import { addExamples } from '../../utils/help.js';
|
|
7
|
+
import { createSpinner, theme, section, kvPair } from '../../utils/ui.js';
|
|
8
|
+
import { AgentCommandOptions } from '../../types/agent.js';
|
|
8
9
|
|
|
9
10
|
const setGroup = new Command('set')
|
|
10
|
-
.description('
|
|
11
|
+
.description('Quickly configure agent properties');
|
|
12
|
+
|
|
13
|
+
addExamples(setGroup, [
|
|
14
|
+
{ description: 'Replace the agent greeting',
|
|
15
|
+
command: 'plazbot agent set greeting agt_AbcDef123 "Hi! How can I help you today?"' },
|
|
16
|
+
{ description: 'Configure tone, style, language, etc. interactively',
|
|
17
|
+
command: 'plazbot agent set instructions agt_AbcDef123' },
|
|
18
|
+
{ description: 'Define the agent persona (name, role, voice)',
|
|
19
|
+
command: 'plazbot agent set persona agt_AbcDef123' },
|
|
20
|
+
]);
|
|
11
21
|
|
|
12
22
|
// Set greeting
|
|
13
23
|
setGroup.command('greeting')
|
|
14
|
-
.description('
|
|
15
|
-
.argument('<agentId>', 'ID
|
|
16
|
-
.argument('<greeting>', '
|
|
17
|
-
.option('--dev', '
|
|
24
|
+
.description('Change the agent greeting')
|
|
25
|
+
.argument('<agentId>', 'Agent ID')
|
|
26
|
+
.argument('<greeting>', 'New greeting')
|
|
27
|
+
.option('--dev', 'Use development environment', false)
|
|
18
28
|
.action(async (agentId: string, greeting: string, options: AgentCommandOptions) => {
|
|
19
29
|
try {
|
|
20
30
|
const credentials = await getStoredCredentials();
|
|
@@ -25,14 +35,14 @@ setGroup.command('greeting')
|
|
|
25
35
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
26
36
|
});
|
|
27
37
|
|
|
28
|
-
const spinner = createSpinner('
|
|
38
|
+
const spinner = createSpinner('Updating greeting...');
|
|
29
39
|
spinner.start();
|
|
30
40
|
await agent.setGreeting(agentId, greeting);
|
|
31
|
-
spinner.succeed('
|
|
32
|
-
logger.label('
|
|
41
|
+
spinner.succeed('Greeting updated');
|
|
42
|
+
logger.label('New greeting', greeting);
|
|
33
43
|
|
|
34
44
|
} catch (error) {
|
|
35
|
-
const message = error instanceof Error ? error.message : '
|
|
45
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
36
46
|
logger.error(message);
|
|
37
47
|
process.exit(1);
|
|
38
48
|
}
|
|
@@ -40,9 +50,9 @@ setGroup.command('greeting')
|
|
|
40
50
|
|
|
41
51
|
// Set instructions (wizard)
|
|
42
52
|
setGroup.command('instructions')
|
|
43
|
-
.description('
|
|
44
|
-
.argument('<agentId>', 'ID
|
|
45
|
-
.option('--dev', '
|
|
53
|
+
.description('Configure agent instructions')
|
|
54
|
+
.argument('<agentId>', 'Agent ID')
|
|
55
|
+
.option('--dev', 'Use development environment', false)
|
|
46
56
|
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
47
57
|
try {
|
|
48
58
|
const credentials = await getStoredCredentials();
|
|
@@ -54,22 +64,22 @@ setGroup.command('instructions')
|
|
|
54
64
|
});
|
|
55
65
|
|
|
56
66
|
// Cargar instrucciones actuales
|
|
57
|
-
const loadSpinner = createSpinner('
|
|
67
|
+
const loadSpinner = createSpinner('Loading...');
|
|
58
68
|
loadSpinner.start();
|
|
59
69
|
const _res1: any = await agent.getAgentById({ id: agentId });
|
|
60
70
|
const agentData = _res1.agent || _res1.data || _res1;
|
|
61
71
|
loadSpinner.stop();
|
|
62
72
|
|
|
63
73
|
const current = agentData.instructions || {};
|
|
64
|
-
console.log(section('
|
|
74
|
+
console.log(section('Instructions - ' + (agentData.name || agentId)));
|
|
65
75
|
|
|
66
76
|
const answers = await (inquirer as any).prompt([
|
|
67
|
-
{ type: 'list', name: 'tone', message: '
|
|
68
|
-
{ type: 'list', name: 'style', message: '
|
|
69
|
-
{ type: 'input', name: 'personality', message: '
|
|
70
|
-
{ type: 'input', name: 'objective', message: '
|
|
71
|
-
{ type: 'list', name: 'language', message: '
|
|
72
|
-
{ type: 'confirm', name: 'emojis', message: '
|
|
77
|
+
{ type: 'list', name: 'tone', message: 'Tone:', choices: ['profesional', 'amigable', 'formal', 'casual', 'tecnico', 'empatico'], default: current.tone || 'profesional' },
|
|
78
|
+
{ type: 'list', name: 'style', message: 'Style:', choices: ['conciso', 'detallado', 'conversacional', 'directo'], default: current.style || 'conciso' },
|
|
79
|
+
{ type: 'input', name: 'personality', message: 'Personality:', default: current.personality || '' },
|
|
80
|
+
{ type: 'input', name: 'objective', message: 'Objective:', default: current.objective || '' },
|
|
81
|
+
{ type: 'list', name: 'language', message: 'Language:', choices: ['Espanol', 'English', 'Portugues'], default: current.language || 'Espanol' },
|
|
82
|
+
{ type: 'confirm', name: 'emojis', message: 'Use emojis?', default: current.emojis === true },
|
|
73
83
|
]);
|
|
74
84
|
|
|
75
85
|
const instructions = {
|
|
@@ -82,13 +92,13 @@ setGroup.command('instructions')
|
|
|
82
92
|
emojis: answers.emojis,
|
|
83
93
|
};
|
|
84
94
|
|
|
85
|
-
const spinner = createSpinner('
|
|
95
|
+
const spinner = createSpinner('Saving instructions...');
|
|
86
96
|
spinner.start();
|
|
87
97
|
await agent.setInstructions(agentId, instructions);
|
|
88
|
-
spinner.succeed('
|
|
98
|
+
spinner.succeed('Instructions updated');
|
|
89
99
|
|
|
90
100
|
} catch (error) {
|
|
91
|
-
const message = error instanceof Error ? error.message : '
|
|
101
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
92
102
|
logger.error(message);
|
|
93
103
|
process.exit(1);
|
|
94
104
|
}
|
|
@@ -96,9 +106,9 @@ setGroup.command('instructions')
|
|
|
96
106
|
|
|
97
107
|
// Set persona (wizard)
|
|
98
108
|
setGroup.command('persona')
|
|
99
|
-
.description('
|
|
100
|
-
.argument('<agentId>', 'ID
|
|
101
|
-
.option('--dev', '
|
|
109
|
+
.description('Configure the agent persona')
|
|
110
|
+
.argument('<agentId>', 'Agent ID')
|
|
111
|
+
.option('--dev', 'Use development environment', false)
|
|
102
112
|
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
103
113
|
try {
|
|
104
114
|
const credentials = await getStoredCredentials();
|
|
@@ -109,7 +119,7 @@ setGroup.command('persona')
|
|
|
109
119
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
110
120
|
});
|
|
111
121
|
|
|
112
|
-
const loadSpinner = createSpinner('
|
|
122
|
+
const loadSpinner = createSpinner('Loading...');
|
|
113
123
|
loadSpinner.start();
|
|
114
124
|
const _res2: any = await agent.getAgentById({ id: agentId });
|
|
115
125
|
const agentData = _res2.agent || _res2.data || _res2;
|
|
@@ -119,18 +129,18 @@ setGroup.command('persona')
|
|
|
119
129
|
console.log(section('Persona - ' + (agentData.name || agentId)));
|
|
120
130
|
|
|
121
131
|
const answers = await (inquirer as any).prompt([
|
|
122
|
-
{ type: 'input', name: 'name', message: '
|
|
123
|
-
{ type: 'input', name: 'role', message: '
|
|
124
|
-
{ type: 'confirm', name: 'speaksInFirstPerson', message: '
|
|
132
|
+
{ type: 'input', name: 'name', message: 'Character name:', default: current.name || '' },
|
|
133
|
+
{ type: 'input', name: 'role', message: 'Role:', default: current.role || '' },
|
|
134
|
+
{ type: 'confirm', name: 'speaksInFirstPerson', message: 'Speak in first person?', default: current.speaksInFirstPerson !== false },
|
|
125
135
|
]);
|
|
126
136
|
|
|
127
|
-
const spinner = createSpinner('
|
|
137
|
+
const spinner = createSpinner('Saving persona...');
|
|
128
138
|
spinner.start();
|
|
129
139
|
await agent.setPersona(agentId, answers);
|
|
130
|
-
spinner.succeed('Persona
|
|
140
|
+
spinner.succeed('Persona updated');
|
|
131
141
|
|
|
132
142
|
} catch (error) {
|
|
133
|
-
const message = error instanceof Error ? error.message : '
|
|
143
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
134
144
|
logger.error(message);
|
|
135
145
|
process.exit(1);
|
|
136
146
|
}
|