plazbot-cli 0.3.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/dist/commands/agent/export.js +25 -2
- package/dist/commands/auth/browser-login.js +121 -0
- package/dist/commands/auth/index.js +5 -1
- package/dist/commands/auth/login.js +1 -3
- package/dist/commands/auth/logout.js +4 -3
- package/dist/commands/auth/status.js +8 -5
- package/dist/commands/auth/workspace.js +73 -0
- package/dist/commands/whatsapp/connect-flow.js +137 -0
- package/dist/commands/whatsapp/connect.js +26 -160
- package/dist/commands/whatsapp/index.js +4 -0
- package/dist/commands/whatsapp/setup.js +242 -0
- package/dist/studio/components/App.js +1 -1
- package/dist/studio/runOneShot.js +2 -2
- package/dist/studio/runRepl.js +1 -1
- package/dist/utils/agent-errors.js +2 -2
- package/dist/utils/banner.js +10 -9
- package/dist/utils/credentials.js +31 -3
- package/dist/utils/open-browser.js +17 -0
- package/package.json +14 -6
- package/.claude/settings.local.json +0 -15
- package/CLAUDE.md +0 -121
- package/agent.config.json +0 -21
- package/dist/studio/components/AgentPanel.js +0 -35
- package/dist/studio/render/json.js +0 -16
- package/dist/studio/whatsapp/api.js +0 -63
- package/dist/studio/whatsapp/polling.js +0 -77
- package/dist/studio/whatsapp/types.js +0 -31
- package/src/cli.ts +0 -57
- package/src/commands/agent/ai-config.ts +0 -164
- package/src/commands/agent/chat.ts +0 -225
- package/src/commands/agent/copy.ts +0 -46
- package/src/commands/agent/create.ts +0 -103
- package/src/commands/agent/delete.ts +0 -71
- package/src/commands/agent/enable-widget.ts +0 -67
- package/src/commands/agent/export.ts +0 -408
- package/src/commands/agent/files.ts +0 -171
- package/src/commands/agent/get.ts +0 -233
- package/src/commands/agent/index.ts +0 -55
- package/src/commands/agent/list.ts +0 -58
- package/src/commands/agent/monitor.ts +0 -375
- package/src/commands/agent/on-message.ts +0 -82
- package/src/commands/agent/set.ts +0 -149
- package/src/commands/agent/templates.ts +0 -892
- package/src/commands/agent/tools.ts +0 -168
- package/src/commands/agent/update.ts +0 -61
- package/src/commands/agent/validate.ts +0 -135
- package/src/commands/agent/wizard.ts +0 -756
- package/src/commands/auth/index.ts +0 -10
- package/src/commands/auth/login.ts +0 -72
- package/src/commands/auth/logout.ts +0 -28
- package/src/commands/auth/status.ts +0 -28
- package/src/commands/portal/add-agent.ts +0 -66
- package/src/commands/portal/add-link.ts +0 -47
- package/src/commands/portal/clear-links.ts +0 -33
- package/src/commands/portal/create.ts +0 -58
- package/src/commands/portal/delete.ts +0 -70
- package/src/commands/portal/get.ts +0 -77
- package/src/commands/portal/index.ts +0 -32
- package/src/commands/portal/list.ts +0 -79
- package/src/commands/portal/update.ts +0 -93
- package/src/commands/whatsapp/broadcast.ts +0 -110
- package/src/commands/whatsapp/channels.ts +0 -109
- package/src/commands/whatsapp/chat.ts +0 -85
- package/src/commands/whatsapp/connect.ts +0 -220
- package/src/commands/whatsapp/delete-webhook.ts +0 -43
- package/src/commands/whatsapp/index.ts +0 -37
- package/src/commands/whatsapp/register-webhook.ts +0 -47
- package/src/commands/whatsapp/send-template.ts +0 -94
- package/src/commands/whatsapp/send.ts +0 -55
- package/src/commands/whatsapp/widget.ts +0 -75
- package/src/commands/workers/deploy.ts +0 -156
- package/src/commands/workers/index.ts +0 -30
- package/src/commands/workers/list.ts +0 -105
- package/src/commands/workers/logs.ts +0 -99
- package/src/commands/workers/remove.ts +0 -103
- package/src/commands/workers/secret.ts +0 -191
- package/src/commands/workers/test.ts +0 -145
- package/src/schemas/agent.config.schema.json +0 -569
- package/src/studio/api/sseClient.ts +0 -91
- package/src/studio/api/studioApi.ts +0 -27
- package/src/studio/api/types.ts +0 -96
- package/src/studio/components/App.tsx +0 -274
- package/src/studio/components/ChatLog.tsx +0 -121
- package/src/studio/components/ConnectCard.tsx +0 -171
- package/src/studio/components/Footer.tsx +0 -38
- package/src/studio/components/Header.tsx +0 -39
- package/src/studio/components/Input.tsx +0 -176
- package/src/studio/components/Message.tsx +0 -87
- package/src/studio/components/Suggestions.tsx +0 -26
- package/src/studio/components/ToolCall.tsx +0 -58
- package/src/studio/connect/api.ts +0 -98
- package/src/studio/connect/polling.ts +0 -94
- package/src/studio/connect/types.ts +0 -141
- package/src/studio/index.ts +0 -58
- package/src/studio/render/markdown.ts +0 -93
- package/src/studio/render/steps.ts +0 -57
- package/src/studio/runOneShot.ts +0 -114
- package/src/studio/runRepl.tsx +0 -82
- package/src/studio/slash/handlers.ts +0 -226
- package/src/studio/slash/parser.ts +0 -41
- package/src/studio/slash/registry.ts +0 -54
- package/src/studio/state/store.ts +0 -279
- package/src/types/agent.ts +0 -63
- package/src/types/auth.ts +0 -9
- package/src/types/common.ts +0 -10
- package/src/types/message.ts +0 -34
- package/src/types/portal.ts +0 -56
- package/src/types/workers.ts +0 -86
- package/src/utils/agent-errors.ts +0 -67
- package/src/utils/api.ts +0 -35
- package/src/utils/banner.ts +0 -99
- package/src/utils/credentials.ts +0 -38
- package/src/utils/help.ts +0 -51
- package/src/utils/logger.ts +0 -40
- package/src/utils/ui.ts +0 -109
- package/tsconfig.json +0 -18
|
@@ -1,375 +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 { theme } from '../../utils/ui.js';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import readline from 'readline';
|
|
9
|
-
import { HubConnectionBuilder, HttpTransportType, HubConnectionState } from '@microsoft/signalr';
|
|
10
|
-
|
|
11
|
-
// Colores por tipo de evento (mismos del MonitorTab frontend)
|
|
12
|
-
const EVENT_COLORS: Record<string, { color: string; label: string }> = {
|
|
13
|
-
msg_in: { color: '#22d3ee', label: 'msg_in' },
|
|
14
|
-
msg_out: { color: '#4ade80', label: 'msg_out' },
|
|
15
|
-
tool_call: { color: '#c084fc', label: 'tool_call' },
|
|
16
|
-
api_req: { color: '#fbbf24', label: 'api_req' },
|
|
17
|
-
api_res: { color: '#fbbf24', label: 'api_res' },
|
|
18
|
-
action: { color: '#f97316', label: 'action' },
|
|
19
|
-
rag: { color: '#60a5fa', label: 'rag' },
|
|
20
|
-
tokens: { color: '#94a3b8', label: 'tokens' },
|
|
21
|
-
error: { color: '#ef4444', label: 'error' },
|
|
22
|
-
model: { color: '#a78bfa', label: 'model' },
|
|
23
|
-
intent: { color: '#a78bfa', label: 'intent' },
|
|
24
|
-
bot_off: { color: '#f97316', label: 'bot_off' },
|
|
25
|
-
session_field: { color: '#a78bfa', label: 'session_field' },
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const DEFAULT_EVENT_COLOR = { color: '#94a3b8', label: 'unknown' };
|
|
29
|
-
|
|
30
|
-
interface AgentLogEvent {
|
|
31
|
-
timestamp: string;
|
|
32
|
-
workspace_id: string;
|
|
33
|
-
agent_id: string;
|
|
34
|
-
contact_id: string;
|
|
35
|
-
contact_name: string;
|
|
36
|
-
session_id: string;
|
|
37
|
-
event_type: string;
|
|
38
|
-
event_title: string;
|
|
39
|
-
event_data: string;
|
|
40
|
-
duration_ms: number;
|
|
41
|
-
level: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getBaseUrl(zone: string, dev: boolean): string {
|
|
45
|
-
if (dev) return 'http://localhost:5090';
|
|
46
|
-
return zone === 'EU' ? 'https://apieu.plazbot.com' : 'https://api.plazbot.com';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function formatTimestamp(ts: string): string {
|
|
50
|
-
try {
|
|
51
|
-
const d = new Date(ts);
|
|
52
|
-
return d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
53
|
-
} catch {
|
|
54
|
-
return ts.substring(11, 19);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function truncate(text: string, maxLen: number): string {
|
|
59
|
-
if (!text) return '';
|
|
60
|
-
return text.length > maxLen ? text.substring(0, maxLen - 3) + '...' : text;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function shortSession(sessionId: string): string {
|
|
64
|
-
if (!sessionId) return '';
|
|
65
|
-
return sessionId.substring(0, 6);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function renderLogLine(
|
|
69
|
-
log: AgentLogEvent,
|
|
70
|
-
opts: { showSession: boolean; jsonMode: boolean },
|
|
71
|
-
lastSessionId: string
|
|
72
|
-
): string {
|
|
73
|
-
// Modo JSON crudo
|
|
74
|
-
if (opts.jsonMode) {
|
|
75
|
-
return JSON.stringify(log);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const config = EVENT_COLORS[log.event_type] || DEFAULT_EVENT_COLOR;
|
|
79
|
-
const colorFn = chalk.hex(config.color);
|
|
80
|
-
const grayFn = chalk.hex('#71717a');
|
|
81
|
-
const dimFn = chalk.hex('#52525b');
|
|
82
|
-
|
|
83
|
-
let lines: string[] = [];
|
|
84
|
-
|
|
85
|
-
// Separador de sesion
|
|
86
|
-
if (lastSessionId && log.session_id && log.session_id !== lastSessionId) {
|
|
87
|
-
lines.push(dimFn(' ' + '─'.repeat(16) + ' new session ' + '─'.repeat(16)));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Linea principal
|
|
91
|
-
const timestamp = grayFn(formatTimestamp(log.timestamp));
|
|
92
|
-
const dot = colorFn('●');
|
|
93
|
-
const eventType = colorFn(config.label.padEnd(14));
|
|
94
|
-
const title = chalk.white(truncate(log.event_title, 80));
|
|
95
|
-
const duration = log.duration_ms > 0 ? dimFn(` ${log.duration_ms}ms`) : '';
|
|
96
|
-
const session = opts.showSession && log.session_id
|
|
97
|
-
? dimFn(` [${shortSession(log.session_id)}]`)
|
|
98
|
-
: '';
|
|
99
|
-
|
|
100
|
-
lines.push(` ${timestamp} ${dot} ${eventType} ${title}${duration}${session}`);
|
|
101
|
-
|
|
102
|
-
// Linea de contacto para mensajes
|
|
103
|
-
if (log.contact_name && (log.event_type === 'msg_in' || log.event_type === 'msg_out')) {
|
|
104
|
-
lines.push(dimFn(' | contact: ') + dimFn(log.contact_name));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return lines.join('\n');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function printHeader(agentName: string) {
|
|
111
|
-
console.log();
|
|
112
|
-
console.log(chalk.hex('#4CAF50')(' ┌' + '─'.repeat(62) + '┐'));
|
|
113
|
-
console.log(
|
|
114
|
-
chalk.hex('#4CAF50')(' │') +
|
|
115
|
-
chalk.bold(` Monitor`) +
|
|
116
|
-
chalk.hex('#4ade80')(' ● Live') +
|
|
117
|
-
' '.repeat(42) +
|
|
118
|
-
chalk.hex('#4CAF50')('│')
|
|
119
|
-
);
|
|
120
|
-
console.log(
|
|
121
|
-
chalk.hex('#4CAF50')(' │') +
|
|
122
|
-
chalk.gray(` Agent: ${truncate(agentName, 44)}`) +
|
|
123
|
-
' '.repeat(Math.max(0, 50 - agentName.length)) +
|
|
124
|
-
chalk.hex('#4CAF50')('│')
|
|
125
|
-
);
|
|
126
|
-
console.log(
|
|
127
|
-
chalk.hex('#4CAF50')(' │') +
|
|
128
|
-
chalk.gray(' Ctrl+C exit | /filter <type> | /clear | /help') +
|
|
129
|
-
' '.repeat(13) +
|
|
130
|
-
chalk.hex('#4CAF50')('│')
|
|
131
|
-
);
|
|
132
|
-
console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(62) + '┘'));
|
|
133
|
-
console.log();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const COMMANDS_HELP = `
|
|
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:')}
|
|
146
|
-
${Object.entries(EVENT_COLORS).map(([key, val]) =>
|
|
147
|
-
` ${chalk.hex(val.color)('●')} ${key}`
|
|
148
|
-
).join('\n')}
|
|
149
|
-
`;
|
|
150
|
-
|
|
151
|
-
export const monitorCommand = new Command('monitor')
|
|
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
|
-
filter?: string;
|
|
162
|
-
session: boolean;
|
|
163
|
-
json: boolean;
|
|
164
|
-
workspace?: string;
|
|
165
|
-
zone?: string;
|
|
166
|
-
dev: boolean;
|
|
167
|
-
}) => {
|
|
168
|
-
try {
|
|
169
|
-
const credentials = await getStoredCredentials();
|
|
170
|
-
|
|
171
|
-
const effectiveWorkspace = options.workspace || credentials.workspace;
|
|
172
|
-
const effectiveZone = (options.zone?.toUpperCase() === 'EU' ? 'EU' : options.zone?.toUpperCase() === 'LA' ? 'LA' : credentials.zone) as 'LA' | 'EU';
|
|
173
|
-
const baseUrl = getBaseUrl(effectiveZone, options.dev);
|
|
174
|
-
|
|
175
|
-
if (options.workspace || options.zone) {
|
|
176
|
-
console.log(chalk.hex('#FFA726')(`\n Support mode: workspace=${effectiveWorkspace} zone=${effectiveZone}`));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Filtros iniciales
|
|
180
|
-
const activeFilters: Set<string> = new Set(
|
|
181
|
-
options.filter ? options.filter.split(',').map(f => f.trim()) : []
|
|
182
|
-
);
|
|
183
|
-
let jsonMode = options.json;
|
|
184
|
-
let lastSessionId = '';
|
|
185
|
-
|
|
186
|
-
// Cargar info del agente
|
|
187
|
-
let agentName = 'Agent';
|
|
188
|
-
try {
|
|
189
|
-
process.stdout.write(chalk.gray(' Connecting to agent...'));
|
|
190
|
-
const agent = new Agent({
|
|
191
|
-
workspaceId: effectiveWorkspace,
|
|
192
|
-
apiKey: credentials.apiKey,
|
|
193
|
-
zone: effectiveZone,
|
|
194
|
-
...(options.dev && { customUrl: 'http://localhost:5090' }),
|
|
195
|
-
});
|
|
196
|
-
const _res: any = await agent.getAgentById({ id: agentId });
|
|
197
|
-
const info = _res.agent || _res.data || _res;
|
|
198
|
-
if (info?.name) agentName = info.name;
|
|
199
|
-
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
200
|
-
} catch {
|
|
201
|
-
process.stdout.write('\r' + ' '.repeat(40) + '\r');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Dibujar header
|
|
205
|
-
if (!jsonMode) {
|
|
206
|
-
console.clear();
|
|
207
|
-
printHeader(agentName);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Conectar a SignalR
|
|
211
|
-
const hubUrl = `${baseUrl}/agentMonitorHub`;
|
|
212
|
-
const connection = new HubConnectionBuilder()
|
|
213
|
-
.withUrl(hubUrl, {
|
|
214
|
-
skipNegotiation: true,
|
|
215
|
-
transport: HttpTransportType.WebSockets,
|
|
216
|
-
})
|
|
217
|
-
.withAutomaticReconnect([0, 2000, 5000, 10000, 30000])
|
|
218
|
-
.build();
|
|
219
|
-
|
|
220
|
-
// Evento de log
|
|
221
|
-
connection.on('agent_log', (log: AgentLogEvent) => {
|
|
222
|
-
// Aplicar filtros
|
|
223
|
-
if (activeFilters.size > 0 && !activeFilters.has(log.event_type)) return;
|
|
224
|
-
|
|
225
|
-
const line = renderLogLine(log, {
|
|
226
|
-
showSession: options.session,
|
|
227
|
-
jsonMode,
|
|
228
|
-
}, lastSessionId);
|
|
229
|
-
|
|
230
|
-
console.log(line);
|
|
231
|
-
lastSessionId = log.session_id || lastSessionId;
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// Eventos de conexion
|
|
235
|
-
connection.onreconnecting(() => {
|
|
236
|
-
if (!jsonMode) {
|
|
237
|
-
console.log(chalk.hex('#FFA726')(' ⟳ Reconnecting...'));
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
connection.onreconnected(() => {
|
|
242
|
-
if (!jsonMode) {
|
|
243
|
-
console.log(chalk.hex('#4ade80')(' ● Reconnected'));
|
|
244
|
-
}
|
|
245
|
-
connection.invoke('JoinAgentMonitor', agentId).catch(() => {});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
connection.onclose(() => {
|
|
249
|
-
if (!jsonMode) {
|
|
250
|
-
console.log(chalk.hex('#ef4444')(' ● Disconnected'));
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// Iniciar conexion
|
|
255
|
-
try {
|
|
256
|
-
await connection.start();
|
|
257
|
-
await connection.invoke('JoinAgentMonitor', agentId);
|
|
258
|
-
if (!jsonMode) {
|
|
259
|
-
console.log(chalk.hex('#4ade80')(' ● Connected to real-time monitor'));
|
|
260
|
-
console.log();
|
|
261
|
-
}
|
|
262
|
-
} catch (err) {
|
|
263
|
-
logger.error(`Could not connect to monitor: ${err instanceof Error ? err.message : err}`);
|
|
264
|
-
process.exit(1);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// readline para comandos interactivos
|
|
268
|
-
const rl = readline.createInterface({
|
|
269
|
-
input: process.stdin,
|
|
270
|
-
output: process.stdout,
|
|
271
|
-
prompt: '',
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// No mostrar prompt para no interferir con el stream
|
|
275
|
-
rl.on('line', (input: string) => {
|
|
276
|
-
const cmd = input.trim().toLowerCase();
|
|
277
|
-
|
|
278
|
-
if (cmd === '/help') {
|
|
279
|
-
console.log(COMMANDS_HELP);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (cmd === '/clear') {
|
|
284
|
-
console.clear();
|
|
285
|
-
printHeader(agentName);
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (cmd === '/json') {
|
|
290
|
-
jsonMode = !jsonMode;
|
|
291
|
-
console.log(chalk.gray(` JSON mode: ${jsonMode ? 'enabled' : 'disabled'}`));
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (cmd === '/filters') {
|
|
296
|
-
if (activeFilters.size === 0) {
|
|
297
|
-
console.log(chalk.gray(' No active filters (showing all)'));
|
|
298
|
-
} else {
|
|
299
|
-
console.log(chalk.gray(' Active filters: ') + chalk.white([...activeFilters].join(', ')));
|
|
300
|
-
}
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (cmd.startsWith('/filter ')) {
|
|
305
|
-
const filterType = cmd.substring(8).trim();
|
|
306
|
-
if (!filterType) {
|
|
307
|
-
console.log(chalk.gray(' Usage: /filter <type> | /filter clear'));
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (filterType === 'clear') {
|
|
311
|
-
activeFilters.clear();
|
|
312
|
-
console.log(chalk.gray(' All filters cleared (showing all)'));
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
if (activeFilters.has(filterType)) {
|
|
316
|
-
activeFilters.delete(filterType);
|
|
317
|
-
console.log(chalk.gray(` Filter removed: ${filterType}`));
|
|
318
|
-
} else {
|
|
319
|
-
activeFilters.add(filterType);
|
|
320
|
-
const config = EVENT_COLORS[filterType];
|
|
321
|
-
if (config) {
|
|
322
|
-
console.log(chalk.hex(config.color)(` ● Filter added: ${filterType}`));
|
|
323
|
-
} else {
|
|
324
|
-
console.log(chalk.gray(` Filter added: ${filterType} (unknown type)`));
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (activeFilters.size > 0) {
|
|
328
|
-
console.log(chalk.gray(' Active: ') + chalk.white([...activeFilters].join(', ')));
|
|
329
|
-
} else {
|
|
330
|
-
console.log(chalk.gray(' No filters (showing all)'));
|
|
331
|
-
}
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// Cierre limpio
|
|
337
|
-
const cleanup = async () => {
|
|
338
|
-
if (!jsonMode) {
|
|
339
|
-
console.log(chalk.gray('\n Closing monitor...'));
|
|
340
|
-
}
|
|
341
|
-
try {
|
|
342
|
-
if (connection.state === HubConnectionState.Connected) {
|
|
343
|
-
await connection.invoke('LeaveAgentMonitor', agentId);
|
|
344
|
-
}
|
|
345
|
-
await connection.stop();
|
|
346
|
-
} catch {
|
|
347
|
-
// Ignorar errores al cerrar
|
|
348
|
-
}
|
|
349
|
-
rl.close();
|
|
350
|
-
if (!jsonMode) {
|
|
351
|
-
console.log(chalk.gray(' Monitor closed.\n'));
|
|
352
|
-
}
|
|
353
|
-
process.exit(0);
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
process.on('SIGINT', cleanup);
|
|
357
|
-
process.on('SIGTERM', cleanup);
|
|
358
|
-
|
|
359
|
-
} catch (error) {
|
|
360
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
361
|
-
logger.error(message);
|
|
362
|
-
process.exit(1);
|
|
363
|
-
}
|
|
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,82 +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, AgentResponse, AgentSource } from '../../types/agent.js';
|
|
7
|
-
import crypto from 'crypto';
|
|
8
|
-
|
|
9
|
-
export const messageCommand = new Command('message')
|
|
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
|
-
question: string;
|
|
18
|
-
sessionId?: string;
|
|
19
|
-
multipleAnswers?: boolean;
|
|
20
|
-
}) => {
|
|
21
|
-
try {
|
|
22
|
-
// Obtener credenciales guardadas
|
|
23
|
-
const credentials = await getStoredCredentials();
|
|
24
|
-
|
|
25
|
-
const agent = new Agent({
|
|
26
|
-
workspaceId: credentials.workspace,
|
|
27
|
-
apiKey: credentials.apiKey,
|
|
28
|
-
zone: credentials.zone,
|
|
29
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Generar un sessionId si no se proporcionó uno
|
|
33
|
-
const sessionId = options.sessionId || crypto.randomUUID();
|
|
34
|
-
|
|
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
|
-
if (options.multipleAnswers) {
|
|
40
|
-
logger.info('Mode: Multiple answers');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const response = await agent.onMessage({
|
|
44
|
-
agentId: agentId,
|
|
45
|
-
question: options.question,
|
|
46
|
-
sessionId,
|
|
47
|
-
multipleAnswers: options.multipleAnswers
|
|
48
|
-
}) as AgentResponse;
|
|
49
|
-
|
|
50
|
-
logger.title('Agent Response');
|
|
51
|
-
console.log(response.answer);
|
|
52
|
-
|
|
53
|
-
if (response.sources && response.sources.length > 0) {
|
|
54
|
-
logger.title('Sources');
|
|
55
|
-
response.sources.forEach((source: AgentSource) => {
|
|
56
|
-
logger.label('Title', source.title || 'Untitled');
|
|
57
|
-
if (source.url) logger.label('URL', source.url);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
logger.title('Session');
|
|
62
|
-
logger.label('ID', sessionId);
|
|
63
|
-
|
|
64
|
-
if (options.dev) {
|
|
65
|
-
logger.warning('\nEnvironment: development');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
} catch (error) {
|
|
69
|
-
const message = error instanceof Error ? error.message : 'Unknown error while sending the message';
|
|
70
|
-
logger.error(message);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
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,149 +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 { createSpinner, theme, section, kvPair } from '../../utils/ui.js';
|
|
8
|
-
import { AgentCommandOptions } from '../../types/agent.js';
|
|
9
|
-
|
|
10
|
-
const setGroup = new Command('set')
|
|
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
|
-
]);
|
|
21
|
-
|
|
22
|
-
// Set greeting
|
|
23
|
-
setGroup.command('greeting')
|
|
24
|
-
.description('Change the agent greeting')
|
|
25
|
-
.argument('<agentId>', 'Agent ID')
|
|
26
|
-
.argument('<greeting>', 'New greeting')
|
|
27
|
-
.option('--dev', 'Use development environment', false)
|
|
28
|
-
.action(async (agentId: string, greeting: string, options: AgentCommandOptions) => {
|
|
29
|
-
try {
|
|
30
|
-
const credentials = await getStoredCredentials();
|
|
31
|
-
const agent = new Agent({
|
|
32
|
-
workspaceId: credentials.workspace,
|
|
33
|
-
apiKey: credentials.apiKey,
|
|
34
|
-
zone: credentials.zone,
|
|
35
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const spinner = createSpinner('Updating greeting...');
|
|
39
|
-
spinner.start();
|
|
40
|
-
await agent.setGreeting(agentId, greeting);
|
|
41
|
-
spinner.succeed('Greeting updated');
|
|
42
|
-
logger.label('New greeting', greeting);
|
|
43
|
-
|
|
44
|
-
} catch (error) {
|
|
45
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
46
|
-
logger.error(message);
|
|
47
|
-
process.exit(1);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Set instructions (wizard)
|
|
52
|
-
setGroup.command('instructions')
|
|
53
|
-
.description('Configure agent instructions')
|
|
54
|
-
.argument('<agentId>', 'Agent ID')
|
|
55
|
-
.option('--dev', 'Use development environment', false)
|
|
56
|
-
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
57
|
-
try {
|
|
58
|
-
const credentials = await getStoredCredentials();
|
|
59
|
-
const agent = new Agent({
|
|
60
|
-
workspaceId: credentials.workspace,
|
|
61
|
-
apiKey: credentials.apiKey,
|
|
62
|
-
zone: credentials.zone,
|
|
63
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Cargar instrucciones actuales
|
|
67
|
-
const loadSpinner = createSpinner('Loading...');
|
|
68
|
-
loadSpinner.start();
|
|
69
|
-
const _res1: any = await agent.getAgentById({ id: agentId });
|
|
70
|
-
const agentData = _res1.agent || _res1.data || _res1;
|
|
71
|
-
loadSpinner.stop();
|
|
72
|
-
|
|
73
|
-
const current = agentData.instructions || {};
|
|
74
|
-
console.log(section('Instructions - ' + (agentData.name || agentId)));
|
|
75
|
-
|
|
76
|
-
const answers = await (inquirer as any).prompt([
|
|
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 },
|
|
83
|
-
]);
|
|
84
|
-
|
|
85
|
-
const instructions = {
|
|
86
|
-
...current,
|
|
87
|
-
tone: answers.tone,
|
|
88
|
-
style: answers.style,
|
|
89
|
-
personality: answers.personality,
|
|
90
|
-
objective: answers.objective,
|
|
91
|
-
language: answers.language,
|
|
92
|
-
emojis: answers.emojis,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const spinner = createSpinner('Saving instructions...');
|
|
96
|
-
spinner.start();
|
|
97
|
-
await agent.setInstructions(agentId, instructions);
|
|
98
|
-
spinner.succeed('Instructions updated');
|
|
99
|
-
|
|
100
|
-
} catch (error) {
|
|
101
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
102
|
-
logger.error(message);
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Set persona (wizard)
|
|
108
|
-
setGroup.command('persona')
|
|
109
|
-
.description('Configure the agent persona')
|
|
110
|
-
.argument('<agentId>', 'Agent ID')
|
|
111
|
-
.option('--dev', 'Use development environment', false)
|
|
112
|
-
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
113
|
-
try {
|
|
114
|
-
const credentials = await getStoredCredentials();
|
|
115
|
-
const agent = new Agent({
|
|
116
|
-
workspaceId: credentials.workspace,
|
|
117
|
-
apiKey: credentials.apiKey,
|
|
118
|
-
zone: credentials.zone,
|
|
119
|
-
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const loadSpinner = createSpinner('Loading...');
|
|
123
|
-
loadSpinner.start();
|
|
124
|
-
const _res2: any = await agent.getAgentById({ id: agentId });
|
|
125
|
-
const agentData = _res2.agent || _res2.data || _res2;
|
|
126
|
-
loadSpinner.stop();
|
|
127
|
-
|
|
128
|
-
const current = agentData.person || {};
|
|
129
|
-
console.log(section('Persona - ' + (agentData.name || agentId)));
|
|
130
|
-
|
|
131
|
-
const answers = await (inquirer as any).prompt([
|
|
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 },
|
|
135
|
-
]);
|
|
136
|
-
|
|
137
|
-
const spinner = createSpinner('Saving persona...');
|
|
138
|
-
spinner.start();
|
|
139
|
-
await agent.setPersona(agentId, answers);
|
|
140
|
-
spinner.succeed('Persona updated');
|
|
141
|
-
|
|
142
|
-
} catch (error) {
|
|
143
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
144
|
-
logger.error(message);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
export const setCommand = setGroup;
|