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,11 +1,12 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import { Agent } from 'plazbot';
|
|
4
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
5
|
-
import { logger } from '../../utils/logger';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { getStoredCredentials } from '../../utils/credentials.js';
|
|
5
|
+
import { logger } from '../../utils/logger.js';
|
|
6
|
+
import { addExamples } from '../../utils/help.js';
|
|
7
|
+
import { theme, section, kvPair, createTable, createSpinner } from '../../utils/ui.js';
|
|
8
|
+
import { AgentCommandOptions } from '../../types/agent.js';
|
|
9
|
+
import { connectChannelFlow, WizardContext } from './wizard.js';
|
|
9
10
|
|
|
10
11
|
interface TemplatePlaceholder {
|
|
11
12
|
key: string;
|
|
@@ -594,57 +595,57 @@ const plantillaVentas: any = {
|
|
|
594
595
|
// Registro de plantillas con sus placeholders
|
|
595
596
|
const TEMPLATES: Template[] = [
|
|
596
597
|
{
|
|
597
|
-
name: '
|
|
598
|
-
description: '
|
|
599
|
-
industry: '
|
|
598
|
+
name: 'Sales Assistant',
|
|
599
|
+
description: 'Agent for sales management, quotes and orders',
|
|
600
|
+
industry: 'Sales',
|
|
600
601
|
placeholders: [
|
|
601
|
-
{ key: '[NOMBRE DE LA EMPRESA]', label: '
|
|
602
|
-
{ key: '[DIRECCION COMPLETA]', label: '
|
|
603
|
-
{ key: '[NUMERO DE TELEFONO]', label: '
|
|
602
|
+
{ key: '[NOMBRE DE LA EMPRESA]', label: 'Your company name' },
|
|
603
|
+
{ key: '[DIRECCION COMPLETA]', label: 'Your company address' },
|
|
604
|
+
{ key: '[NUMERO DE TELEFONO]', label: 'Contact phone' },
|
|
604
605
|
],
|
|
605
606
|
config: plantillaVentas,
|
|
606
607
|
},
|
|
607
608
|
{
|
|
608
|
-
name: '
|
|
609
|
-
description: '
|
|
610
|
-
industry: '
|
|
609
|
+
name: 'IT Technical Support',
|
|
610
|
+
description: 'Agent for technical support, tickets and problem resolution',
|
|
611
|
+
industry: 'Technology',
|
|
611
612
|
placeholders: [
|
|
612
|
-
{ key: '[NOMBRE DE LA EMPRESA]', label: '
|
|
613
|
-
{ key: '[NUMERO DE TELEFONO]', label: '
|
|
614
|
-
{ key: '[EMAIL DE SOPORTE]', label: '
|
|
613
|
+
{ key: '[NOMBRE DE LA EMPRESA]', label: 'Your company name' },
|
|
614
|
+
{ key: '[NUMERO DE TELEFONO]', label: 'Support phone' },
|
|
615
|
+
{ key: '[EMAIL DE SOPORTE]', label: 'Support email (e.g. support@company.com)' },
|
|
615
616
|
],
|
|
616
617
|
config: plantillaSoporteIT,
|
|
617
618
|
},
|
|
618
619
|
{
|
|
619
|
-
name: '
|
|
620
|
-
description: '
|
|
621
|
-
industry: '
|
|
620
|
+
name: 'Clinic Assistant',
|
|
621
|
+
description: 'Agent for clinics: medical appointments, schedules and specialties',
|
|
622
|
+
industry: 'Health',
|
|
622
623
|
placeholders: [
|
|
623
|
-
{ key: '[NOMBRE DE LA CLINICA]', label: '
|
|
624
|
-
{ key: '[DIRECCION COMPLETA]', label: '
|
|
625
|
-
{ key: '[NUMERO DE TELEFONO]', label: '
|
|
624
|
+
{ key: '[NOMBRE DE LA CLINICA]', label: 'Your clinic name' },
|
|
625
|
+
{ key: '[DIRECCION COMPLETA]', label: 'Clinic address' },
|
|
626
|
+
{ key: '[NUMERO DE TELEFONO]', label: 'Clinic phone' },
|
|
626
627
|
],
|
|
627
628
|
config: plantillaClinica,
|
|
628
629
|
},
|
|
629
630
|
{
|
|
630
|
-
name: '
|
|
631
|
-
description: '
|
|
632
|
-
industry: '
|
|
631
|
+
name: 'Restaurant Assistant',
|
|
632
|
+
description: 'Agent for restaurants: reservations, menu and delivery',
|
|
633
|
+
industry: 'Gastronomy',
|
|
633
634
|
placeholders: [
|
|
634
|
-
{ key: '[NOMBRE DEL RESTAURANTE]', label: '
|
|
635
|
-
{ key: '[DIRECCION COMPLETA]', label: '
|
|
636
|
-
{ key: '[NUMERO DE TELEFONO]', label: '
|
|
635
|
+
{ key: '[NOMBRE DEL RESTAURANTE]', label: 'Your restaurant name' },
|
|
636
|
+
{ key: '[DIRECCION COMPLETA]', label: 'Restaurant address' },
|
|
637
|
+
{ key: '[NUMERO DE TELEFONO]', label: 'Restaurant phone' },
|
|
637
638
|
],
|
|
638
639
|
config: plantillaRestaurante,
|
|
639
640
|
},
|
|
640
641
|
{
|
|
641
|
-
name: '
|
|
642
|
-
description: '
|
|
643
|
-
industry: '
|
|
642
|
+
name: 'Real Estate Assistant',
|
|
643
|
+
description: 'Agent for real estate: properties, viewings and advisory',
|
|
644
|
+
industry: 'Real Estate',
|
|
644
645
|
placeholders: [
|
|
645
|
-
{ key: '[NOMBRE DE LA INMOBILIARIA]', label: '
|
|
646
|
-
{ key: '[DIRECCION COMPLETA]', label: '
|
|
647
|
-
{ key: '[NUMERO DE TELEFONO]', label: '
|
|
646
|
+
{ key: '[NOMBRE DE LA INMOBILIARIA]', label: 'Your real estate name' },
|
|
647
|
+
{ key: '[DIRECCION COMPLETA]', label: 'Office address' },
|
|
648
|
+
{ key: '[NUMERO DE TELEFONO]', label: 'Contact phone' },
|
|
648
649
|
],
|
|
649
650
|
config: plantillaInmobiliario,
|
|
650
651
|
},
|
|
@@ -675,13 +676,13 @@ function replacePlaceholders(obj: any, replacements: Record<string, string>): an
|
|
|
675
676
|
}
|
|
676
677
|
|
|
677
678
|
export const templatesCommand = new Command('templates')
|
|
678
|
-
.description('
|
|
679
|
-
.option('--dev', '
|
|
680
|
-
.option('--json', '
|
|
679
|
+
.description('Create an agent from pre-configured templates')
|
|
680
|
+
.option('--dev', 'Use development environment', false)
|
|
681
|
+
.option('--json', 'Only show the resulting JSON without creating the agent', false)
|
|
681
682
|
.action(async (options: AgentCommandOptions & { json?: boolean }) => {
|
|
682
683
|
try {
|
|
683
|
-
console.log(section('
|
|
684
|
-
console.log(theme.muted('
|
|
684
|
+
console.log(section('Agent templates'));
|
|
685
|
+
console.log(theme.muted(' Create a pre-configured agent in seconds\n'));
|
|
685
686
|
|
|
686
687
|
const rows = TEMPLATES.map((t, i) => [
|
|
687
688
|
String(i + 1),
|
|
@@ -689,16 +690,16 @@ export const templatesCommand = new Command('templates')
|
|
|
689
690
|
t.industry,
|
|
690
691
|
t.description,
|
|
691
692
|
]);
|
|
692
|
-
console.log(createTable(['#', '
|
|
693
|
+
console.log(createTable(['#', 'Name', 'Industry', 'Description'], rows));
|
|
693
694
|
|
|
694
695
|
// Paso 1: Seleccionar plantilla
|
|
695
696
|
const { selected } = await (inquirer as any).prompt([{
|
|
696
697
|
type: 'list',
|
|
697
698
|
name: 'selected',
|
|
698
|
-
message: '
|
|
699
|
+
message: 'Select a template:',
|
|
699
700
|
choices: [
|
|
700
701
|
...TEMPLATES.map((t, i) => ({ name: `${t.name} (${t.industry})`, value: i })),
|
|
701
|
-
{ name: '
|
|
702
|
+
{ name: 'Cancel', value: -1 },
|
|
702
703
|
],
|
|
703
704
|
}]);
|
|
704
705
|
|
|
@@ -707,15 +708,15 @@ export const templatesCommand = new Command('templates')
|
|
|
707
708
|
const template = TEMPLATES[selected];
|
|
708
709
|
|
|
709
710
|
console.log(section(`${template.name}`));
|
|
710
|
-
console.log(kvPair('
|
|
711
|
+
console.log(kvPair('Industry', template.industry));
|
|
711
712
|
console.log(kvPair('Persona', `${template.config.person.name} - ${template.config.person.role}`));
|
|
712
|
-
console.log(kvPair('
|
|
713
|
-
console.log(kvPair('Tool Calling', '
|
|
713
|
+
console.log(kvPair('Actions', String(template.config.actions.length)));
|
|
714
|
+
console.log(kvPair('Tool Calling', 'Enabled'));
|
|
714
715
|
console.log();
|
|
715
716
|
|
|
716
717
|
// Paso 2: Personalizar placeholders
|
|
717
|
-
console.log(theme.bold('\n
|
|
718
|
-
console.log(theme.muted('
|
|
718
|
+
console.log(theme.bold('\n Quick customization'));
|
|
719
|
+
console.log(theme.muted(' Fill in your business details:\n'));
|
|
719
720
|
|
|
720
721
|
const placeholderAnswers: Record<string, string> = {};
|
|
721
722
|
for (const ph of template.placeholders) {
|
|
@@ -723,17 +724,17 @@ export const templatesCommand = new Command('templates')
|
|
|
723
724
|
type: 'input',
|
|
724
725
|
name: 'value',
|
|
725
726
|
message: `${ph.label}:`,
|
|
726
|
-
validate: (v: string) => v.trim().length > 0 || '
|
|
727
|
+
validate: (v: string) => v.trim().length > 0 || 'This field is required',
|
|
727
728
|
}]);
|
|
728
729
|
placeholderAnswers[ph.key] = value.trim();
|
|
729
730
|
}
|
|
730
731
|
|
|
731
732
|
// Paso 3: Canales (WhatsApp, Messenger, Instagram, Telegram)
|
|
732
|
-
console.log(theme.bold('\n
|
|
733
|
+
console.log(theme.bold('\n Channel connection'));
|
|
733
734
|
const { wantChannels } = await (inquirer as any).prompt([{
|
|
734
735
|
type: 'confirm',
|
|
735
736
|
name: 'wantChannels',
|
|
736
|
-
message: '
|
|
737
|
+
message: 'Connect channels (WhatsApp, Messenger, Instagram, Telegram)?',
|
|
737
738
|
default: true,
|
|
738
739
|
}]);
|
|
739
740
|
|
|
@@ -750,11 +751,11 @@ export const templatesCommand = new Command('templates')
|
|
|
750
751
|
}
|
|
751
752
|
|
|
752
753
|
// Paso 4: API Key de OpenAI
|
|
753
|
-
console.log(theme.bold('\n
|
|
754
|
+
console.log(theme.bold('\n AI configuration'));
|
|
754
755
|
const { configureApiKey } = await (inquirer as any).prompt([{
|
|
755
756
|
type: 'confirm',
|
|
756
757
|
name: 'configureApiKey',
|
|
757
|
-
message: '
|
|
758
|
+
message: 'Configure your OpenAI API Key now? (required for the agent to work)',
|
|
758
759
|
default: true,
|
|
759
760
|
}]);
|
|
760
761
|
|
|
@@ -763,9 +764,9 @@ export const templatesCommand = new Command('templates')
|
|
|
763
764
|
const { key } = await (inquirer as any).prompt([{
|
|
764
765
|
type: 'password',
|
|
765
766
|
name: 'key',
|
|
766
|
-
message: 'API Key
|
|
767
|
+
message: 'OpenAI API Key (sk-...):',
|
|
767
768
|
mask: '*',
|
|
768
|
-
validate: (v: string) => v.trim().length > 0 || '
|
|
769
|
+
validate: (v: string) => v.trim().length > 0 || 'The API Key is required',
|
|
769
770
|
}]);
|
|
770
771
|
apiToken = key.trim();
|
|
771
772
|
}
|
|
@@ -774,7 +775,7 @@ export const templatesCommand = new Command('templates')
|
|
|
774
775
|
const { timezone } = await (inquirer as any).prompt([{
|
|
775
776
|
type: 'input',
|
|
776
777
|
name: 'timezone',
|
|
777
|
-
message: '
|
|
778
|
+
message: 'Timezone (e.g. America/Lima, America/Bogota, America/Mexico_City):',
|
|
778
779
|
default: template.config.timezone,
|
|
779
780
|
}]);
|
|
780
781
|
|
|
@@ -796,33 +797,33 @@ export const templatesCommand = new Command('templates')
|
|
|
796
797
|
|
|
797
798
|
// Si es --json, solo mostrar y salir
|
|
798
799
|
if (options.json) {
|
|
799
|
-
console.log(section('JSON
|
|
800
|
+
console.log(section('Configuration JSON'));
|
|
800
801
|
logger.json(finalConfig);
|
|
801
802
|
return;
|
|
802
803
|
}
|
|
803
804
|
|
|
804
805
|
// Paso 6: Confirmacion
|
|
805
|
-
console.log(section('
|
|
806
|
-
console.log(kvPair('
|
|
806
|
+
console.log(section('Summary'));
|
|
807
|
+
console.log(kvPair('Template', template.name));
|
|
807
808
|
for (const ph of template.placeholders) {
|
|
808
809
|
console.log(kvPair(ph.label, placeholderAnswers[ph.key]));
|
|
809
810
|
}
|
|
810
|
-
console.log(kvPair('
|
|
811
|
-
console.log(kvPair('API Key
|
|
812
|
-
console.log(kvPair('
|
|
813
|
-
console.log(kvPair('
|
|
814
|
-
console.log(kvPair('
|
|
811
|
+
console.log(kvPair('Channels', connectedChannels.length > 0 ? connectedChannels.map(c => `${c.channel} (${c.key})`).join(', ') : 'Not configured'));
|
|
812
|
+
console.log(kvPair('OpenAI API Key', apiToken ? 'Configured' : 'Not configured (the agent will not work without it)'));
|
|
813
|
+
console.log(kvPair('Timezone', timezone));
|
|
814
|
+
console.log(kvPair('Actions', String(finalConfig.actions.length)));
|
|
815
|
+
console.log(kvPair('AI', `${finalConfig.aiProviders[0].provider} / ${finalConfig.aiProviders[0].model}`));
|
|
815
816
|
console.log();
|
|
816
817
|
|
|
817
818
|
const { confirm } = await (inquirer as any).prompt([{
|
|
818
819
|
type: 'confirm',
|
|
819
820
|
name: 'confirm',
|
|
820
|
-
message: '
|
|
821
|
+
message: 'Create the agent with this configuration?',
|
|
821
822
|
default: true,
|
|
822
823
|
}]);
|
|
823
824
|
|
|
824
825
|
if (!confirm) {
|
|
825
|
-
logger.warning('
|
|
826
|
+
logger.warning('Creation cancelled');
|
|
826
827
|
return;
|
|
827
828
|
}
|
|
828
829
|
|
|
@@ -836,49 +837,56 @@ export const templatesCommand = new Command('templates')
|
|
|
836
837
|
|
|
837
838
|
finalConfig.zone = credentials.zone;
|
|
838
839
|
|
|
839
|
-
const spinner = createSpinner('
|
|
840
|
+
const spinner = createSpinner('Creating agent...');
|
|
840
841
|
spinner.start();
|
|
841
842
|
|
|
842
843
|
const result = await agent.addAgent(finalConfig);
|
|
843
844
|
|
|
844
|
-
spinner.succeed('
|
|
845
|
+
spinner.succeed('Agent created successfully');
|
|
845
846
|
|
|
846
|
-
logger.title('
|
|
847
|
+
logger.title('Agent details');
|
|
847
848
|
if (result.agentId) {
|
|
848
849
|
logger.label('ID', result.agentId);
|
|
849
850
|
}
|
|
850
|
-
logger.label('
|
|
851
|
-
logger.label('
|
|
851
|
+
logger.label('Name', finalConfig.name);
|
|
852
|
+
logger.label('Industry', template.industry);
|
|
852
853
|
if (connectedChannels.length > 0) {
|
|
853
|
-
logger.label('
|
|
854
|
+
logger.label('Channels', connectedChannels.map(c => `${c.channel} (${c.key})`).join(', '));
|
|
854
855
|
}
|
|
855
|
-
logger.label('
|
|
856
|
+
logger.label('Actions', String(finalConfig.actions.length));
|
|
856
857
|
|
|
857
858
|
console.log();
|
|
858
|
-
console.log(section('
|
|
859
|
+
console.log(section('Next steps'));
|
|
859
860
|
if (connectedChannels.length === 0) {
|
|
860
|
-
console.log(theme.bold(' 1.') + '
|
|
861
|
-
console.log(theme.bold(' 2.') + '
|
|
861
|
+
console.log(theme.bold(' 1.') + ' Connect channels from: ' + theme.success('plazbot agent chat -a <agentId>'));
|
|
862
|
+
console.log(theme.bold(' 2.') + ' Or connect from the platform in Settings > Integrations');
|
|
862
863
|
} else {
|
|
863
|
-
console.log(theme.bold(' 1.') + '
|
|
864
|
+
console.log(theme.bold(' 1.') + ' Your agent already has channels connected and enabled');
|
|
864
865
|
}
|
|
865
|
-
console.log(theme.bold(` ${connectedChannels.length === 0 ? '3' : '2'}.`) + '
|
|
866
|
+
console.log(theme.bold(` ${connectedChannels.length === 0 ? '3' : '2'}.`) + ' Add your OpenAI API Key if you have not yet');
|
|
866
867
|
console.log();
|
|
867
868
|
|
|
868
869
|
if (!apiToken) {
|
|
869
|
-
logger.warning('
|
|
870
|
+
logger.warning('Remember to configure your OpenAI API Key for the agent to work:');
|
|
870
871
|
logger.dim(`plazbot agent ai-config ${result.agentId || '<agentId>'}`);
|
|
871
872
|
console.log();
|
|
872
873
|
}
|
|
873
|
-
logger.dim('
|
|
874
|
+
logger.dim('Test agent: plazbot agent chat -a ' + (result.agentId || '<agentId>'));
|
|
874
875
|
|
|
875
876
|
if (options.dev) {
|
|
876
|
-
logger.warning('
|
|
877
|
+
logger.warning('Environment: development');
|
|
877
878
|
}
|
|
878
879
|
|
|
879
880
|
} catch (error) {
|
|
880
|
-
const message = error instanceof Error ? error.message : '
|
|
881
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
881
882
|
logger.error(message);
|
|
882
883
|
process.exit(1);
|
|
883
884
|
}
|
|
884
885
|
});
|
|
886
|
+
|
|
887
|
+
addExamples(templatesCommand, [
|
|
888
|
+
{ description: 'Pick a template and create the agent interactively',
|
|
889
|
+
command: 'plazbot agent templates' },
|
|
890
|
+
{ description: 'Preview the resulting JSON without creating the agent',
|
|
891
|
+
command: 'plazbot agent templates --json' },
|
|
892
|
+
]);
|
|
@@ -1,15 +1,16 @@
|
|
|
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, createTable, theme, section, kvPair, statusBadge } from '../../utils/ui.js';
|
|
8
|
+
import { AgentCommandOptions } from '../../types/agent.js';
|
|
8
9
|
|
|
9
10
|
export const toolsCommand = new Command('tools')
|
|
10
|
-
.description('
|
|
11
|
-
.argument('<agentId>', 'ID
|
|
12
|
-
.option('--dev', '
|
|
11
|
+
.description('Manage agent Tool Calling tools')
|
|
12
|
+
.argument('<agentId>', 'Agent ID')
|
|
13
|
+
.option('--dev', 'Use development environment', false)
|
|
13
14
|
.action(async (agentId: string, options: AgentCommandOptions) => {
|
|
14
15
|
try {
|
|
15
16
|
const credentials = await getStoredCredentials();
|
|
@@ -20,42 +21,42 @@ export const toolsCommand = new Command('tools')
|
|
|
20
21
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
const spinner = createSpinner('
|
|
24
|
+
const spinner = createSpinner('Loading agent...');
|
|
24
25
|
spinner.start();
|
|
25
26
|
const _res: any = await agent.getAgentById({ id: agentId });
|
|
26
27
|
const agentData = _res.agent || _res.data || _res;
|
|
27
28
|
spinner.stop();
|
|
28
29
|
|
|
29
30
|
console.log(section('Tool Calling - ' + (agentData.name || agentId)));
|
|
30
|
-
console.log(kvPair('
|
|
31
|
+
console.log(kvPair('Status', agentData.useToolCalling ? theme.success('Enabled') : theme.error('Disabled')));
|
|
31
32
|
|
|
32
33
|
// Servicios
|
|
33
34
|
const services = agentData.services || [];
|
|
34
35
|
if (services.length > 0) {
|
|
35
|
-
console.log(section('
|
|
36
|
+
console.log(section('Services (API calls)'));
|
|
36
37
|
const rows = services.map((s: any) => [
|
|
37
38
|
s.intent,
|
|
38
39
|
s.method || 'POST',
|
|
39
40
|
s.endpoint ? s.endpoint.substring(0, 40) + '...' : 'N/A',
|
|
40
41
|
statusBadge(s.enabled !== false),
|
|
41
42
|
]);
|
|
42
|
-
console.log(createTable(['Intent', 'Method', 'Endpoint', '
|
|
43
|
+
console.log(createTable(['Intent', 'Method', 'Endpoint', 'Status'], rows));
|
|
43
44
|
} else {
|
|
44
|
-
console.log(theme.muted('\n No
|
|
45
|
+
console.log(theme.muted('\n No services configured'));
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
// Acciones
|
|
48
49
|
const actions = agentData.actions || [];
|
|
49
50
|
if (actions.length > 0) {
|
|
50
|
-
console.log(section('
|
|
51
|
+
console.log(section('Actions'));
|
|
51
52
|
const rows = actions.map((a: any) => [
|
|
52
53
|
a.intent,
|
|
53
54
|
(a.action || []).map((ac: any) => ac.type).join(', '),
|
|
54
55
|
statusBadge(a.enabled !== false),
|
|
55
56
|
]);
|
|
56
|
-
console.log(createTable(['Intent', '
|
|
57
|
+
console.log(createTable(['Intent', 'Type', 'Status'], rows));
|
|
57
58
|
} else {
|
|
58
|
-
console.log(theme.muted('\n No
|
|
59
|
+
console.log(theme.muted('\n No actions configured'));
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// Menu de opciones
|
|
@@ -63,33 +64,33 @@ export const toolsCommand = new Command('tools')
|
|
|
63
64
|
const { action } = await (inquirer as any).prompt([{
|
|
64
65
|
type: 'list',
|
|
65
66
|
name: 'action',
|
|
66
|
-
message: '
|
|
67
|
+
message: 'What would you like to do?',
|
|
67
68
|
choices: [
|
|
68
|
-
{ name: '
|
|
69
|
-
{ name: '
|
|
70
|
-
{ name: agentData.useToolCalling ? '
|
|
71
|
-
{ name: '
|
|
69
|
+
{ name: 'Add service (API call)', value: 'add-service' },
|
|
70
|
+
{ name: 'Add action', value: 'add-action' },
|
|
71
|
+
{ name: agentData.useToolCalling ? 'Disable Tool Calling' : 'Enable Tool Calling', value: 'toggle' },
|
|
72
|
+
{ name: 'Exit', value: 'exit' },
|
|
72
73
|
],
|
|
73
74
|
}]);
|
|
74
75
|
|
|
75
76
|
if (action === 'exit') return;
|
|
76
77
|
|
|
77
78
|
if (action === 'toggle') {
|
|
78
|
-
const toggleSpinner = createSpinner('
|
|
79
|
+
const toggleSpinner = createSpinner('Updating...');
|
|
79
80
|
toggleSpinner.start();
|
|
80
81
|
const { id: _i1, _id: _o1, ...updatedConfig } = { ...agentData, useToolCalling: !agentData.useToolCalling };
|
|
81
82
|
await agent.updateAgent(agentId, updatedConfig);
|
|
82
|
-
toggleSpinner.succeed(`Tool Calling ${!agentData.useToolCalling ? '
|
|
83
|
+
toggleSpinner.succeed(`Tool Calling ${!agentData.useToolCalling ? 'enabled' : 'disabled'}`);
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
if (action === 'add-service') {
|
|
87
88
|
const svc = await (inquirer as any).prompt([
|
|
88
|
-
{ type: 'input', name: 'intent', message: '
|
|
89
|
-
{ type: 'input', name: 'reference', message: '
|
|
90
|
-
{ type: 'list', name: 'method', message: '
|
|
91
|
-
{ type: 'input', name: 'endpoint', message: 'URL
|
|
92
|
-
{ type: 'input', name: 'responseMessage', message: '
|
|
89
|
+
{ type: 'input', name: 'intent', message: 'Service name/intent:', validate: (v: string) => v.length > 0 || 'Required' },
|
|
90
|
+
{ type: 'input', name: 'reference', message: 'Keywords:', default: '' },
|
|
91
|
+
{ type: 'list', name: 'method', message: 'HTTP method:', choices: ['GET', 'POST'] },
|
|
92
|
+
{ type: 'input', name: 'endpoint', message: 'Endpoint URL:', validate: (v: string) => v.length > 0 || 'Required' },
|
|
93
|
+
{ type: 'input', name: 'responseMessage', message: 'Response message:', default: '' },
|
|
93
94
|
]);
|
|
94
95
|
|
|
95
96
|
const newService = {
|
|
@@ -108,33 +109,33 @@ export const toolsCommand = new Command('tools')
|
|
|
108
109
|
|
|
109
110
|
const updatedServices = [...services, newService];
|
|
110
111
|
const { id: _i2, _id: _o2, ...updatedConfig } = { ...agentData, services: updatedServices, useToolCalling: true };
|
|
111
|
-
const updateSpinner = createSpinner('
|
|
112
|
+
const updateSpinner = createSpinner('Saving service...');
|
|
112
113
|
updateSpinner.start();
|
|
113
114
|
await agent.updateAgent(agentId, updatedConfig);
|
|
114
|
-
updateSpinner.succeed(`
|
|
115
|
+
updateSpinner.succeed(`Service "${svc.intent}" added`);
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
if (action === 'add-action') {
|
|
118
119
|
const act = await (inquirer as any).prompt([
|
|
119
|
-
{ type: 'input', name: 'intent', message: '
|
|
120
|
-
{ type: 'input', name: 'reference', message: '
|
|
120
|
+
{ type: 'input', name: 'intent', message: 'Action name/intent:', validate: (v: string) => v.length > 0 || 'Required' },
|
|
121
|
+
{ type: 'input', name: 'reference', message: 'Keywords:', default: '' },
|
|
121
122
|
{
|
|
122
|
-
type: 'list', name: 'actionType', message: '
|
|
123
|
+
type: 'list', name: 'actionType', message: 'Action type:',
|
|
123
124
|
choices: [
|
|
124
|
-
{ name: '
|
|
125
|
-
{ name: '
|
|
126
|
-
{ name: '
|
|
127
|
-
{ name: '
|
|
128
|
-
{ name: '
|
|
129
|
-
{ name: '
|
|
130
|
-
{ name: '
|
|
131
|
-
{ name: '
|
|
132
|
-
{ name: '
|
|
133
|
-
{ name: '
|
|
125
|
+
{ name: 'Schedule event', value: 'action.event.add' },
|
|
126
|
+
{ name: 'Update event (reschedule)', value: 'action.event.update' },
|
|
127
|
+
{ name: 'List events', value: 'action.event.list' },
|
|
128
|
+
{ name: 'Delete event (cancel)', value: 'action.event.delete' },
|
|
129
|
+
{ name: 'Add tag', value: 'action.tag' },
|
|
130
|
+
{ name: 'Change stage', value: 'action.stage' },
|
|
131
|
+
{ name: 'Hand off to human agent', value: 'action.agentShutDown' },
|
|
132
|
+
{ name: 'Mark as resolved', value: 'action.solved' },
|
|
133
|
+
{ name: 'Assign agent', value: 'action.asign' },
|
|
134
|
+
{ name: 'Segmentation', value: 'action.segmentation' },
|
|
134
135
|
],
|
|
135
136
|
},
|
|
136
|
-
{ type: 'input', name: 'actionValue', message: '
|
|
137
|
-
{ type: 'input', name: 'responseMessage', message: '
|
|
137
|
+
{ type: 'input', name: 'actionValue', message: 'Value (optional):', default: '' },
|
|
138
|
+
{ type: 'input', name: 'responseMessage', message: 'Response message:', default: '' },
|
|
138
139
|
]);
|
|
139
140
|
|
|
140
141
|
const newAction = {
|
|
@@ -148,15 +149,20 @@ export const toolsCommand = new Command('tools')
|
|
|
148
149
|
|
|
149
150
|
const updatedActions = [...actions, newAction];
|
|
150
151
|
const { id: _i3, _id: _o3, ...updatedConfig } = { ...agentData, actions: updatedActions, useToolCalling: true };
|
|
151
|
-
const updateSpinner = createSpinner('
|
|
152
|
+
const updateSpinner = createSpinner('Saving action...');
|
|
152
153
|
updateSpinner.start();
|
|
153
154
|
await agent.updateAgent(agentId, updatedConfig);
|
|
154
|
-
updateSpinner.succeed(`
|
|
155
|
+
updateSpinner.succeed(`Action "${act.intent}" added`);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
} catch (error) {
|
|
158
|
-
const message = error instanceof Error ? error.message : '
|
|
159
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
159
160
|
logger.error(message);
|
|
160
161
|
process.exit(1);
|
|
161
162
|
}
|
|
162
163
|
});
|
|
164
|
+
|
|
165
|
+
addExamples(toolsCommand, [
|
|
166
|
+
{ description: 'View services/actions and add new ones interactively',
|
|
167
|
+
command: 'plazbot agent tools agt_AbcDef123' },
|
|
168
|
+
]);
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Agent } from 'plazbot';
|
|
3
|
-
import { getStoredCredentials } from '../../utils/credentials';
|
|
4
|
-
import { logger } from '../../utils/logger';
|
|
5
|
-
import {
|
|
3
|
+
import { getStoredCredentials } from '../../utils/credentials.js';
|
|
4
|
+
import { logger } from '../../utils/logger.js';
|
|
5
|
+
import { addExamples } from '../../utils/help.js';
|
|
6
|
+
import { AgentCommandOptions } from '../../types/agent.js';
|
|
6
7
|
import fs from 'fs/promises';
|
|
7
8
|
|
|
8
9
|
export const updateCommand = new Command('update')
|
|
9
|
-
.description('
|
|
10
|
-
.argument('<agentId>', 'ID
|
|
11
|
-
.argument('<configPath>', '
|
|
12
|
-
.option('--dev', '
|
|
10
|
+
.description('Update an existing agent in Plazbot')
|
|
11
|
+
.argument('<agentId>', 'Agent ID to update')
|
|
12
|
+
.argument('<configPath>', 'Path to the agent JSON configuration file')
|
|
13
|
+
.option('--dev', 'Use development environment', false)
|
|
13
14
|
.action(async (agentId: string, configPath: string, options: AgentCommandOptions) => {
|
|
14
15
|
try {
|
|
15
16
|
// Obtener credenciales guardadas
|
|
16
17
|
const credentials = await getStoredCredentials();
|
|
17
|
-
|
|
18
|
+
|
|
18
19
|
// Leer archivo de configuración del agente
|
|
19
20
|
let agentConfig;
|
|
20
21
|
try {
|
|
21
22
|
const fileContent = await fs.readFile(configPath, 'utf-8');
|
|
22
23
|
agentConfig = JSON.parse(fileContent);
|
|
23
24
|
} catch (error) {
|
|
24
|
-
const errorMessage = error instanceof Error ? error.message : '
|
|
25
|
-
throw new Error(`Error
|
|
25
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
26
|
+
throw new Error(`Error reading configuration file: ${errorMessage}`);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
// Crear instancia del agente con las credenciales guardadas
|
|
@@ -33,21 +34,28 @@ export const updateCommand = new Command('update')
|
|
|
33
34
|
...(options.dev && { customUrl: "http://localhost:5090" })
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
logger.dim('
|
|
37
|
-
|
|
37
|
+
logger.dim('Updating agent...');
|
|
38
|
+
|
|
38
39
|
// Actualizar el agente
|
|
39
40
|
const result = await agent.updateAgent(agentId, agentConfig);
|
|
40
|
-
|
|
41
|
-
logger.success('
|
|
42
|
-
logger.info(`
|
|
43
|
-
|
|
41
|
+
|
|
42
|
+
logger.success('Agent updated successfully');
|
|
43
|
+
logger.info(`Message: ${result.message}`);
|
|
44
|
+
|
|
44
45
|
if (options.dev) {
|
|
45
|
-
logger.warning('
|
|
46
|
+
logger.warning('Environment: development');
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
|
|
48
49
|
} catch (error) {
|
|
49
|
-
const message = error instanceof Error ? error.message : '
|
|
50
|
+
const message = error instanceof Error ? error.message : 'Unknown error while updating the agent';
|
|
50
51
|
logger.error(message);
|
|
51
52
|
process.exit(1);
|
|
52
53
|
}
|
|
53
|
-
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
addExamples(updateCommand, [
|
|
57
|
+
{ description: 'Push a new configuration to the agent',
|
|
58
|
+
command: 'plazbot agent update agt_AbcDef123 ./agent.json' },
|
|
59
|
+
{ description: 'Tip: export → edit → update workflow',
|
|
60
|
+
command: 'plazbot agent export agt_AbcDef123 -o agent.json && plazbot agent update agt_AbcDef123 ./agent.json' },
|
|
61
|
+
]);
|