plazbot-cli 0.2.25 → 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 +59 -55
- 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 +48 -36
- 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,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const ui_1 = require("../../utils/ui");
|
|
12
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
13
|
-
const fs_1 = __importDefault(require("fs"));
|
|
14
|
-
const path_1 = __importDefault(require("path"));
|
|
15
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { Agent } from 'plazbot';
|
|
3
|
+
import { getStoredCredentials } from '../../utils/credentials.js';
|
|
4
|
+
import { logger } from '../../utils/logger.js';
|
|
5
|
+
import { addExamples } from '../../utils/help.js';
|
|
6
|
+
import { createSpinner } from '../../utils/ui.js';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import inquirer from 'inquirer';
|
|
16
11
|
// Campos validos segun el schema de agentValidation.ts (additionalProperties: false)
|
|
17
12
|
const VALID_AGENT_FIELDS = new Set([
|
|
18
13
|
'name', 'description', 'prompt', 'zone', 'timezone', 'buffer',
|
|
@@ -184,34 +179,34 @@ function cleanAgentForExport(agentData) {
|
|
|
184
179
|
}
|
|
185
180
|
return cleaned;
|
|
186
181
|
}
|
|
187
|
-
|
|
188
|
-
.description('
|
|
189
|
-
.argument('<agentId>', 'ID
|
|
190
|
-
.option('-w, --workspace <id>', '
|
|
191
|
-
.option('-z, --zone <zone>', '
|
|
192
|
-
.option('-o, --output <path>', '
|
|
193
|
-
.option('--no-channels', '
|
|
194
|
-
.option('--no-ai', '
|
|
195
|
-
.option('--dev', '
|
|
182
|
+
export const exportCommand = new Command('export')
|
|
183
|
+
.description('Export a clean agent configuration (compatible with import)')
|
|
184
|
+
.argument('<agentId>', 'Agent ID to export')
|
|
185
|
+
.option('-w, --workspace <id>', 'Source workspace ID (overrides local config)')
|
|
186
|
+
.option('-z, --zone <zone>', 'Zone LA or EU (overrides local config)')
|
|
187
|
+
.option('-o, --output <path>', 'Output file path (.json)')
|
|
188
|
+
.option('--no-channels', 'Exclude channels from export')
|
|
189
|
+
.option('--no-ai', 'Exclude custom AI configuration')
|
|
190
|
+
.option('--dev', 'Use development environment', false)
|
|
196
191
|
.action(async (agentId, options) => {
|
|
197
192
|
try {
|
|
198
|
-
const credentials = await
|
|
193
|
+
const credentials = await getStoredCredentials();
|
|
199
194
|
const effectiveWorkspace = options.workspace || credentials.workspace;
|
|
200
195
|
const effectiveZone = (options.zone?.toUpperCase() === 'EU' ? 'EU' : options.zone?.toUpperCase() === 'LA' ? 'LA' : credentials.zone);
|
|
201
196
|
if (options.workspace || options.zone) {
|
|
202
|
-
console.log(
|
|
197
|
+
console.log(chalk.hex('#FFA726')(`\n Support mode: workspace=${effectiveWorkspace} zone=${effectiveZone}`));
|
|
203
198
|
}
|
|
204
|
-
const agent = new
|
|
199
|
+
const agent = new Agent({
|
|
205
200
|
workspaceId: effectiveWorkspace,
|
|
206
201
|
apiKey: credentials.apiKey,
|
|
207
202
|
zone: effectiveZone,
|
|
208
203
|
...(options.dev && { customUrl: 'http://localhost:5090' }),
|
|
209
204
|
});
|
|
210
|
-
const spinner =
|
|
205
|
+
const spinner = createSpinner('Fetching agent...');
|
|
211
206
|
spinner.start();
|
|
212
207
|
const response = await agent.getAgentById({ id: agentId });
|
|
213
208
|
const agentData = response.agent || response.data || response;
|
|
214
|
-
spinner.succeed('
|
|
209
|
+
spinner.succeed('Agent fetched');
|
|
215
210
|
// Limpiar para exportacion
|
|
216
211
|
const cleaned = cleanAgentForExport(agentData);
|
|
217
212
|
// Aplicar opciones de exclusion
|
|
@@ -225,54 +220,64 @@ exports.exportCommand = new commander_1.Command('export')
|
|
|
225
220
|
const jsonOutput = JSON.stringify(cleaned, null, 2);
|
|
226
221
|
// Guardar en archivo o mostrar en consola
|
|
227
222
|
if (options.output) {
|
|
228
|
-
const outputPath =
|
|
229
|
-
|
|
230
|
-
console.log(
|
|
223
|
+
const outputPath = path.resolve(options.output);
|
|
224
|
+
fs.writeFileSync(outputPath, jsonOutput, 'utf-8');
|
|
225
|
+
console.log(chalk.hex('#4ade80')(`\n Exported to: ${outputPath}`));
|
|
231
226
|
}
|
|
232
227
|
else {
|
|
233
228
|
console.log();
|
|
234
229
|
console.log(jsonOutput);
|
|
235
230
|
}
|
|
236
231
|
console.log();
|
|
237
|
-
console.log(
|
|
238
|
-
console.log(
|
|
239
|
-
console.log(
|
|
232
|
+
console.log(chalk.gray(' This JSON is compatible with:'));
|
|
233
|
+
console.log(chalk.gray(' - plazbot agent create <file.json>'));
|
|
234
|
+
console.log(chalk.gray(' - Importing JSON in the platform (AgentTraining)'));
|
|
240
235
|
console.log();
|
|
241
236
|
}
|
|
242
237
|
catch (error) {
|
|
243
|
-
const message = error instanceof Error ? error.message : '
|
|
244
|
-
|
|
238
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
239
|
+
logger.error(message);
|
|
245
240
|
process.exit(1);
|
|
246
241
|
}
|
|
247
242
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
243
|
+
addExamples(exportCommand, [
|
|
244
|
+
{ description: 'Print the cleaned JSON to stdout',
|
|
245
|
+
command: 'plazbot agent export agt_AbcDef123' },
|
|
246
|
+
{ description: 'Write the cleaned JSON to a file',
|
|
247
|
+
command: 'plazbot agent export agt_AbcDef123 -o ./agent.json' },
|
|
248
|
+
{ description: 'Export without channels nor AI credentials (portable JSON)',
|
|
249
|
+
command: 'plazbot agent export agt_AbcDef123 -o ./agent.json --no-channels --no-ai' },
|
|
250
|
+
{ description: 'Export from a different workspace (support mode)',
|
|
251
|
+
command: 'plazbot agent export agt_AbcDef123 -w wok_Other123 -z LA -o ./agent.json' },
|
|
252
|
+
]);
|
|
253
|
+
export const crossCopyCommand = new Command('cross-copy')
|
|
254
|
+
.description('Copy an agent from one workspace to another')
|
|
255
|
+
.argument('<agentId>', 'Agent ID to copy')
|
|
256
|
+
.requiredOption('--from-workspace <id>', 'Source workspace ID')
|
|
257
|
+
.requiredOption('--to-workspace <id>', 'Target workspace ID')
|
|
258
|
+
.option('--from-zone <zone>', 'Source workspace zone (LA or EU)', 'LA')
|
|
259
|
+
.option('--to-zone <zone>', 'Target workspace zone (LA or EU)', 'LA')
|
|
260
|
+
.option('--no-channels', 'Do not copy channels (recommended)')
|
|
261
|
+
.option('--no-ai', 'Do not copy custom AI configuration')
|
|
262
|
+
.option('--dev', 'Use development environment', false)
|
|
258
263
|
.action(async (agentId, options) => {
|
|
259
264
|
try {
|
|
260
|
-
const credentials = await
|
|
265
|
+
const credentials = await getStoredCredentials();
|
|
261
266
|
const fromZone = (options.fromZone.toUpperCase() === 'EU' ? 'EU' : 'LA');
|
|
262
267
|
const toZone = (options.toZone.toUpperCase() === 'EU' ? 'EU' : 'LA');
|
|
263
268
|
console.log();
|
|
264
|
-
console.log(
|
|
265
|
-
console.log(
|
|
266
|
-
console.log(
|
|
269
|
+
console.log(chalk.hex('#4CAF50')(' ┌' + '─'.repeat(58) + '┐'));
|
|
270
|
+
console.log(chalk.hex('#4CAF50')(' │') + chalk.bold(' Copy agent between workspaces').padEnd(68) + chalk.hex('#4CAF50')('│'));
|
|
271
|
+
console.log(chalk.hex('#4CAF50')(' └' + '─'.repeat(58) + '┘'));
|
|
267
272
|
console.log();
|
|
268
|
-
console.log(
|
|
269
|
-
console.log(
|
|
270
|
-
console.log(
|
|
273
|
+
console.log(chalk.gray(` Source: ${options.fromWorkspace} (${fromZone})`));
|
|
274
|
+
console.log(chalk.gray(` Target: ${options.toWorkspace} (${toZone})`));
|
|
275
|
+
console.log(chalk.gray(` Agent: ${agentId}`));
|
|
271
276
|
console.log();
|
|
272
277
|
// 1. Obtener agente del workspace origen
|
|
273
|
-
const spinnerGet =
|
|
278
|
+
const spinnerGet = createSpinner('Fetching agent from source workspace...');
|
|
274
279
|
spinnerGet.start();
|
|
275
|
-
const sourceAgent = new
|
|
280
|
+
const sourceAgent = new Agent({
|
|
276
281
|
workspaceId: options.fromWorkspace,
|
|
277
282
|
apiKey: credentials.apiKey,
|
|
278
283
|
zone: fromZone,
|
|
@@ -281,10 +286,10 @@ exports.crossCopyCommand = new commander_1.Command('cross-copy')
|
|
|
281
286
|
const response = await sourceAgent.getAgentById({ id: agentId });
|
|
282
287
|
const agentData = response.agent || response.data || response;
|
|
283
288
|
if (!agentData || !agentData.name) {
|
|
284
|
-
spinnerGet.fail('
|
|
289
|
+
spinnerGet.fail('Agent not found in source workspace');
|
|
285
290
|
process.exit(1);
|
|
286
291
|
}
|
|
287
|
-
spinnerGet.succeed(`
|
|
292
|
+
spinnerGet.succeed(`Agent fetched: ${agentData.name}`);
|
|
288
293
|
// 2. Limpiar JSON
|
|
289
294
|
const cleaned = cleanAgentForExport(agentData);
|
|
290
295
|
// Ajustar zona al destino
|
|
@@ -302,28 +307,28 @@ exports.crossCopyCommand = new commander_1.Command('cross-copy')
|
|
|
302
307
|
cleaned.enableWidget = false;
|
|
303
308
|
// 3. Mostrar resumen
|
|
304
309
|
console.log();
|
|
305
|
-
console.log(
|
|
306
|
-
console.log(
|
|
307
|
-
console.log(
|
|
308
|
-
console.log(
|
|
309
|
-
console.log(
|
|
310
|
-
console.log(
|
|
311
|
-
console.log(
|
|
310
|
+
console.log(chalk.bold(' Configuration to copy:'));
|
|
311
|
+
console.log(chalk.gray(` Name: ${cleaned.name}`));
|
|
312
|
+
console.log(chalk.gray(` Target zone: ${cleaned.zone}`));
|
|
313
|
+
console.log(chalk.gray(` Channels: ${cleaned.channels?.length || 0}`));
|
|
314
|
+
console.log(chalk.gray(` Services: ${cleaned.services?.length || 0}`));
|
|
315
|
+
console.log(chalk.gray(` Actions: ${cleaned.actions?.length || 0}`));
|
|
316
|
+
console.log(chalk.gray(` Custom AI: ${cleaned.customAIConfig ? 'Yes' : 'No'}`));
|
|
312
317
|
console.log();
|
|
313
|
-
const { confirm } = await
|
|
318
|
+
const { confirm } = await inquirer.prompt([{
|
|
314
319
|
type: 'confirm',
|
|
315
320
|
name: 'confirm',
|
|
316
|
-
message: '
|
|
321
|
+
message: 'Create this agent in the target workspace?',
|
|
317
322
|
default: true,
|
|
318
323
|
}]);
|
|
319
324
|
if (!confirm) {
|
|
320
|
-
console.log(
|
|
325
|
+
console.log(chalk.gray(' Operation cancelled.'));
|
|
321
326
|
return;
|
|
322
327
|
}
|
|
323
328
|
// 4. Crear en workspace destino
|
|
324
|
-
const spinnerCreate =
|
|
329
|
+
const spinnerCreate = createSpinner('Creating agent in target workspace...');
|
|
325
330
|
spinnerCreate.start();
|
|
326
|
-
const targetAgent = new
|
|
331
|
+
const targetAgent = new Agent({
|
|
327
332
|
workspaceId: options.toWorkspace,
|
|
328
333
|
apiKey: credentials.apiKey,
|
|
329
334
|
zone: toZone,
|
|
@@ -331,22 +336,30 @@ exports.crossCopyCommand = new commander_1.Command('cross-copy')
|
|
|
331
336
|
});
|
|
332
337
|
const result = await targetAgent.addAgent(cleaned);
|
|
333
338
|
if (result?.success === false) {
|
|
334
|
-
spinnerCreate.fail(`Error: ${result.message || '
|
|
339
|
+
spinnerCreate.fail(`Error: ${result.message || 'Could not create the agent'}`);
|
|
335
340
|
process.exit(1);
|
|
336
341
|
}
|
|
337
342
|
const newId = result?.agentId || result?.id || result?.data?.agentId;
|
|
338
|
-
spinnerCreate.succeed('
|
|
343
|
+
spinnerCreate.succeed('Agent created successfully');
|
|
339
344
|
console.log();
|
|
340
345
|
if (newId) {
|
|
341
|
-
console.log(
|
|
346
|
+
console.log(chalk.hex('#4ade80')(` New ID: ${newId}`));
|
|
342
347
|
}
|
|
343
|
-
console.log(
|
|
344
|
-
console.log(
|
|
348
|
+
console.log(chalk.gray(' Widget disabled by default.'));
|
|
349
|
+
console.log(chalk.gray(' Channels must be configured manually in the target workspace.'));
|
|
345
350
|
console.log();
|
|
346
351
|
}
|
|
347
352
|
catch (error) {
|
|
348
|
-
const message = error instanceof Error ? error.message : '
|
|
349
|
-
|
|
353
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
354
|
+
logger.error(message);
|
|
350
355
|
process.exit(1);
|
|
351
356
|
}
|
|
352
357
|
});
|
|
358
|
+
addExamples(crossCopyCommand, [
|
|
359
|
+
{ description: 'Copy an agent between two LA workspaces (skip channels)',
|
|
360
|
+
command: 'plazbot agent cross-copy agt_AbcDef123 --from-workspace wok_Source123 --to-workspace wok_Target456' },
|
|
361
|
+
{ description: 'Copy across zones (LA → EU)',
|
|
362
|
+
command: 'plazbot agent cross-copy agt_AbcDef123 --from-workspace wok_Source123 --from-zone LA --to-workspace wok_Target456 --to-zone EU' },
|
|
363
|
+
{ description: 'Copy preserving channels and AI providers',
|
|
364
|
+
command: 'plazbot agent cross-copy agt_AbcDef123 --from-workspace wok_Source123 --to-workspace wok_Target456 --channels --ai' },
|
|
365
|
+
]);
|
|
@@ -1,70 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { Agent } from 'plazbot';
|
|
3
|
+
import { getStoredCredentials } from '../../utils/credentials.js';
|
|
4
|
+
import { logger } from '../../utils/logger.js';
|
|
5
|
+
import { addExamples } from '../../utils/help.js';
|
|
6
|
+
import { createSpinner, createTable, theme, section } from '../../utils/ui.js';
|
|
7
|
+
const filesGroup = new Command('files')
|
|
8
|
+
.description('Manage files in the agent knowledge base');
|
|
9
|
+
addExamples(filesGroup, [
|
|
10
|
+
{ description: 'List the knowledge-base files of an agent',
|
|
11
|
+
command: 'plazbot agent files list agt_AbcDef123' },
|
|
12
|
+
{ description: 'Add a remote PDF/DOC to the knowledge base',
|
|
13
|
+
command: 'plazbot agent files add agt_AbcDef123 -u https://files.example.com/manual.pdf -r manual -t docs,onboarding' },
|
|
14
|
+
{ description: 'Check whether a file finished processing',
|
|
15
|
+
command: 'plazbot agent files status file_AbcDef123' },
|
|
16
|
+
{ description: 'Remove a file from the knowledge base',
|
|
17
|
+
command: 'plazbot agent files delete agt_AbcDef123 file_AbcDef123' },
|
|
18
|
+
]);
|
|
11
19
|
// Listar archivos
|
|
12
20
|
filesGroup.command('list')
|
|
13
|
-
.description('
|
|
14
|
-
.argument('<agentId>', 'ID
|
|
15
|
-
.option('--dev', '
|
|
21
|
+
.description('List agent files')
|
|
22
|
+
.argument('<agentId>', 'Agent ID')
|
|
23
|
+
.option('--dev', 'Use development environment', false)
|
|
16
24
|
.action(async (agentId, options) => {
|
|
17
25
|
try {
|
|
18
|
-
const credentials = await
|
|
19
|
-
const agent = new
|
|
26
|
+
const credentials = await getStoredCredentials();
|
|
27
|
+
const agent = new Agent({
|
|
20
28
|
workspaceId: credentials.workspace,
|
|
21
29
|
apiKey: credentials.apiKey,
|
|
22
30
|
zone: credentials.zone,
|
|
23
31
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
24
32
|
});
|
|
25
|
-
const spinner =
|
|
33
|
+
const spinner = createSpinner('Loading files...');
|
|
26
34
|
spinner.start();
|
|
27
35
|
const _res = await agent.getAgentById({ id: agentId });
|
|
28
36
|
const agentData = _res.agent || _res.data || _res;
|
|
29
37
|
spinner.stop();
|
|
30
38
|
const files = agentData.files || [];
|
|
31
|
-
console.log(
|
|
39
|
+
console.log(section('Files - ' + (agentData.name || agentId)));
|
|
32
40
|
if (files.length === 0) {
|
|
33
|
-
console.log(
|
|
34
|
-
console.log(
|
|
41
|
+
console.log(theme.muted('\n No files in the knowledge base'));
|
|
42
|
+
console.log(theme.muted(' Use: plazbot agent files add <agentId> --url <url>\n'));
|
|
35
43
|
return;
|
|
36
44
|
}
|
|
37
45
|
const rows = files.map((f) => [
|
|
38
46
|
f.fileId || f.id || 'N/A',
|
|
39
|
-
f.name || f.reference || '
|
|
47
|
+
f.name || f.reference || 'Untitled',
|
|
40
48
|
(f.tags || []).join(', ') || '-',
|
|
41
49
|
]);
|
|
42
|
-
console.log(
|
|
50
|
+
console.log(createTable(['ID', 'Name', 'Tags'], rows));
|
|
43
51
|
}
|
|
44
52
|
catch (error) {
|
|
45
|
-
const message = error instanceof Error ? error.message : '
|
|
46
|
-
|
|
53
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
54
|
+
logger.error(message);
|
|
47
55
|
process.exit(1);
|
|
48
56
|
}
|
|
49
57
|
});
|
|
50
58
|
// Agregar archivo
|
|
51
59
|
filesGroup.command('add')
|
|
52
|
-
.description('
|
|
53
|
-
.argument('<agentId>', 'ID
|
|
54
|
-
.requiredOption('-u, --url <url>', 'URL
|
|
55
|
-
.option('-r, --reference <name>', '
|
|
56
|
-
.option('-t, --tags <tags>', '
|
|
57
|
-
.option('--dev', '
|
|
60
|
+
.description('Add a file to the knowledge base')
|
|
61
|
+
.argument('<agentId>', 'Agent ID')
|
|
62
|
+
.requiredOption('-u, --url <url>', 'File URL (PDF, DOC, DOCX)')
|
|
63
|
+
.option('-r, --reference <name>', 'Reference name', 'documento')
|
|
64
|
+
.option('-t, --tags <tags>', 'Comma-separated tags', '')
|
|
65
|
+
.option('--dev', 'Use development environment', false)
|
|
58
66
|
.action(async (agentId, options) => {
|
|
59
67
|
try {
|
|
60
|
-
const credentials = await
|
|
61
|
-
const agent = new
|
|
68
|
+
const credentials = await getStoredCredentials();
|
|
69
|
+
const agent = new Agent({
|
|
62
70
|
workspaceId: credentials.workspace,
|
|
63
71
|
apiKey: credentials.apiKey,
|
|
64
72
|
zone: credentials.zone,
|
|
65
73
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
66
74
|
});
|
|
67
|
-
const spinner =
|
|
75
|
+
const spinner = createSpinner('Uploading file...');
|
|
68
76
|
spinner.start();
|
|
69
77
|
const tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : [];
|
|
70
78
|
const result = await agent.addFile({
|
|
@@ -73,71 +81,71 @@ filesGroup.command('add')
|
|
|
73
81
|
agentId,
|
|
74
82
|
tags,
|
|
75
83
|
});
|
|
76
|
-
spinner.succeed('
|
|
84
|
+
spinner.succeed('File added');
|
|
77
85
|
if (result?.fileId) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
logger.label('File ID', result.fileId);
|
|
87
|
+
logger.dim('The file is being processed. Check status with:');
|
|
88
|
+
logger.dim(`plazbot agent files status ${result.fileId}`);
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
91
|
catch (error) {
|
|
84
|
-
const message = error instanceof Error ? error.message : '
|
|
85
|
-
|
|
92
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
93
|
+
logger.error(message);
|
|
86
94
|
process.exit(1);
|
|
87
95
|
}
|
|
88
96
|
});
|
|
89
97
|
// Verificar estado
|
|
90
98
|
filesGroup.command('status')
|
|
91
|
-
.description('
|
|
92
|
-
.argument('<fileId>', 'ID
|
|
93
|
-
.option('--dev', '
|
|
99
|
+
.description('Check the processing status of a file')
|
|
100
|
+
.argument('<fileId>', 'File ID')
|
|
101
|
+
.option('--dev', 'Use development environment', false)
|
|
94
102
|
.action(async (fileId, options) => {
|
|
95
103
|
try {
|
|
96
|
-
const credentials = await
|
|
97
|
-
const agent = new
|
|
104
|
+
const credentials = await getStoredCredentials();
|
|
105
|
+
const agent = new Agent({
|
|
98
106
|
workspaceId: credentials.workspace,
|
|
99
107
|
apiKey: credentials.apiKey,
|
|
100
108
|
zone: credentials.zone,
|
|
101
109
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
102
110
|
});
|
|
103
|
-
const spinner =
|
|
111
|
+
const spinner = createSpinner('Checking...');
|
|
104
112
|
spinner.start();
|
|
105
113
|
const result = await agent.validateFile({ fileId });
|
|
106
114
|
spinner.stop();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
logger.title('File status');
|
|
116
|
+
logger.label('File ID', fileId);
|
|
117
|
+
logger.label('Status', result?.status ? 'Completed' : 'Processing');
|
|
110
118
|
}
|
|
111
119
|
catch (error) {
|
|
112
|
-
const message = error instanceof Error ? error.message : '
|
|
113
|
-
|
|
120
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
121
|
+
logger.error(message);
|
|
114
122
|
process.exit(1);
|
|
115
123
|
}
|
|
116
124
|
});
|
|
117
125
|
// Eliminar archivo
|
|
118
126
|
filesGroup.command('delete')
|
|
119
|
-
.description('
|
|
120
|
-
.argument('<agentId>', 'ID
|
|
121
|
-
.argument('<fileId>', 'ID
|
|
122
|
-
.option('--dev', '
|
|
127
|
+
.description('Delete a file from the knowledge base')
|
|
128
|
+
.argument('<agentId>', 'Agent ID')
|
|
129
|
+
.argument('<fileId>', 'File ID')
|
|
130
|
+
.option('--dev', 'Use development environment', false)
|
|
123
131
|
.action(async (agentId, fileId, options) => {
|
|
124
132
|
try {
|
|
125
|
-
const credentials = await
|
|
126
|
-
const agent = new
|
|
133
|
+
const credentials = await getStoredCredentials();
|
|
134
|
+
const agent = new Agent({
|
|
127
135
|
workspaceId: credentials.workspace,
|
|
128
136
|
apiKey: credentials.apiKey,
|
|
129
137
|
zone: credentials.zone,
|
|
130
138
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
131
139
|
});
|
|
132
|
-
const spinner =
|
|
140
|
+
const spinner = createSpinner('Deleting file...');
|
|
133
141
|
spinner.start();
|
|
134
142
|
await agent.deleteFile({ fileId, agentId });
|
|
135
|
-
spinner.succeed('
|
|
143
|
+
spinner.succeed('File deleted');
|
|
136
144
|
}
|
|
137
145
|
catch (error) {
|
|
138
|
-
const message = error instanceof Error ? error.message : '
|
|
139
|
-
|
|
146
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
147
|
+
logger.error(message);
|
|
140
148
|
process.exit(1);
|
|
141
149
|
}
|
|
142
150
|
});
|
|
143
|
-
|
|
151
|
+
export const filesCommand = filesGroup;
|